2017-03-29 23 views
0

PDFを生成した後に、SQLにクエリを送信するとブラウザに表示されるというコードがあります。しかし、私は、ページ内のPDFビューアにファイルを表示し、ブラウザのリーダーを使用しないようにしています。ビューアはDIVの中にあります。添付された画像に表示されている例を見ることができます。これはテストとして実行され、ストリーミングではなくローカルシステムからのファイルを表示します。この関数は、Response.BinaryWrite(bytes);生成されたPDFをブラウザビューアに送信します。代わりにDIVの中のビューアに表示するにはどうすればいいですか?生成されたPDFファイルを、ブラウザではなくDIV内のリーダーにストリーミングする方法はありますか?

string reportLabel = lbReports.Text; 

document.Add(table); 
document.Close(); 
byte[] bytes = memoryStream.ToArray(); 

Response.Clear(); 
Response.AddHeader("Content-Disposition", "inline"); 

Response.Buffer = true; 
Response.Cache.SetCacheability(HttpCacheability.NoCache); 
Response.BinaryWrite(bytes); 

これは、DIVで生成されたPDFファイルを表示する必要がありますコードです:ここ

string embed = "<object data=\"{0}\" type=\"application/pdf\" width=\"698px\" height=\"450px\">"; 
embed += "If you are unable to view file, you can download from <a href = \"{0}\">here</a>"; 
embed += " or download <a target = \"_blank\" href = \"http://get.adobe.com/reader/\">Adobe PDF Reader</a> to view the file."; 
embed += "</object>"; 
ltEmbed.Text = string.Format(embed, ("blabla.pdf")); /*it shows this PDF as local file just for test*/ 
memoryStream.Close(); 
this.Context.ApplicationInstance.CompleteRequest(); 

画像:sample

アイデアが一時的に生成されたファイルとユーザーを持つことがあるだろうそれを保存するかどうかを決定します。私は他の選択肢を試しましたが、特にそれがDIVの内部にある場合はうまくいかないようです。つまり、私は動的PDFファイルを表示するためにltEmbed.Text = string.Format(embed, ...);

答えて

0

を使用しています。試してください&私に教えてください。

DESIGN

<div id="pdfPopup" style="display: none;"> 
    <a href="Javascript:void(0);" id="cl" onclick="document.getElementById('pdfPopup').style.display ='none';" 
     class="closebtn2" style="z-index: 1111111;"> 
     <img src="images/btnClose.png" alt="" /> 
    </a> 

    <div class="overlay" style="visibility: visible !important;"> 
    </div> 

    <div id="popUpContainer" style="border-radius: 8px; -webkit-border-radius: 8px; -moz-border-radius: 8px; 
     background-color: #fff; width: 1000px; height: 600px; top: 20px; left: 50%; margin-left: -500px; 
     overflow: auto; position: absolute; z-index: 1111111;"> 
     <object data="" type="application/pdf" width="100%" height="600px"> 
     </object> 
    </div> 

</div> 

JS

function DisplayPDF() 
{ 
     var PDFServerPath = document.getElementById('<%=hdnPdfPath.ClientID %>').value; 
     var x = document.getElementsByTagName('object')[0]; 
     x.setAttribute("data", PDFServerPath); 
     document.getElementById('pdfPopup').style.display = "block"; 
    } 

コード

ScriptManager.RegisterStartupScript(Me, Me.GetType(), "DisplayPDF", "DisplayPDF();", True) 
0

私は私がやった、タスクの同じ種類を行うにoppurtunityを持っていましたMVC

私のコントローラメソッドのコードは、この

 byte[] fileContent = Content; 
     string base64 = Convert.ToBase64String(fileContent); 
     Response.Headers.Remove("Content-Disposition"); 
     Response.Buffer = true; 
     Response.ContentType = "application/pdf"; 
     Response.Headers.Add("Content-Disposition", "inline; filename=MyPdfFile.pdf"); 
     return File(fileContent, "applicaton/pdf"); 

のように見え、私のjavascriptのは、長い研究の後

 var iframe = document.createElement('iframe'); 
     iframe.frameBorder = 0; 
     iframe.width = "890px"; 
     iframe.height = "550px"; 
     iframe.id = "frameForMyPdf"; 
     iframe.setAttribute("src", "/Home/GetPDFContent?PdfId=101"); 
     document.getElementById("divPdfPreviewPopup").appendChild(iframe); 
関連する問題