Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将生成的PDF文件流式传输到DIV内的读取器而不是浏览器?_C#_Asp.net_Adobe_Pdfviewer - Fatal编程技术网

C# 如何将生成的PDF文件流式传输到DIV内的读取器而不是浏览器?

C# 如何将生成的PDF文件流式传输到DIV内的读取器而不是浏览器?,c#,asp.net,adobe,pdfviewer,C#,Asp.net,Adobe,Pdfviewer,我有以下代码,生成PDF后,向SQL提交查询将显示在浏览器中。但我想在页面中的PDF查看器中显示文件,而不是使用浏览器阅读器。查看器位于一个DIV中。您可以看到所附图像中显示的示例,我将其作为测试运行,以显示来自本地系统的文件,而不是流。此函数为Response.BinaryWrite(字节);将生成的PDF发送到浏览器查看器。我如何才能让它显示在DIV内部的查看器中 string reportLabel = lbReports.Text; document.Add(table); docum

我有以下代码,生成PDF后,向SQL提交查询将显示在浏览器中。但我想在页面中的PDF查看器中显示文件,而不是使用浏览器阅读器。查看器位于一个DIV中。您可以看到所附图像中显示的示例,我将其作为测试运行,以显示来自本地系统的文件,而不是流。此函数为Response.BinaryWrite(字节);将生成的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();
string-embed=”“;
嵌入+=“如果无法查看文件,可以从下载”;
嵌入+=“或下载以查看文件。”;
嵌入+=”;
ltEmbed.Text=string.Format(嵌入(“blabla.pdf”)/*它将此PDF显示为本地文件,仅供测试使用*/
memoryStream.Close();
this.Context.ApplicationInstance.CompleteRequest();
图片如下:


其想法是临时生成文件,用户将决定是否保存该文件。我尝试过其他选项,但似乎都不起作用,尤其是在DIV中。换句话说,我希望使用
ltEmbed.Text=string.Format(嵌入,…)显示动态PDF文件

我们已在项目中使用。试试&让我知道

设计


我有机会做同样的任务,我在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);

经过长时间的研究,有人向我建议了一些解决方法,因此我在这里与解决方案分享了这个链接,对我来说,它工作得非常完美

 ScriptManager.RegisterStartupScript(Me, Me.GetType(), "DisplayPDF", "DisplayPDF();", True)
        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"); 
        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);