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, ...);