简体   繁体   English

IE不会在浏览器中显示生成的PDF

[英]IE will not display generated PDF in browser

I've tried many things to get this to work, if I use如果我使用,我已经尝试了很多事情来让它工作

Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", newFileInfo.Name));

instead of代替

Response.AddHeader("Content-Disposition", string.Format("inline; filename={0}", newFileInfo.Name));

It works, but I need this to display in the browser window to work properly.它可以工作,但我需要在浏览器 window 中显示才能正常工作。 The inline view works properly in Chrome.内联视图在 Chrome 中正常工作。 I've tried using Response.BinaryWrite and Response.WriteFile and it made no difference.我试过使用 Response.BinaryWrite 和 Response.WriteFile 并没有什么区别。

I'm using Internet Explorer 9.我正在使用 Internet Explorer 9。

Here is my code:这是我的代码:

    Response.Clear();
    Response.ClearHeaders();
    Response.ClearContent();

    Response.Buffer = true;

    Response.ContentType = "application/pdf";
    Response.AddHeader("Pragma", "public");
    Response.AddHeader("expires", "0");
    Response.AddHeader("Cache-Control", "no-cache");
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    string filePath = Request["file"];
    string signatureFile = Request["SignatureImage"];
    double xPos = Convert.ToDouble(Request["X-Pos"]);
    double yPos = Convert.ToDouble(Request["Y-Pos"]);
    double scale = Convert.ToDouble(Request["Scale"]);

    if (!string.IsNullOrEmpty(filePath))
    {
        try
        {                
            string newFile = PDFTools.SignPDF(filePath, signatureFile, xPos, yPos, scale, tempDirectory);
            var newFileInfo = new FileInfo(newFile);
            Response.AddHeader("Content-Disposition", string.Format("inline; filename={0}", newFileInfo.Name));
            Response.AddHeader("content-length", newFileInfo.Length.ToString());

            Response.TransmitFile(newFile);
            Response.Flush();
            Response.Close();
        }
        catch (Exception ex)
        {
            Debug.WriteLine("Error: " + ex.Message);
            Debug.WriteLine("at " + ex.StackTrace);
        }
        finally
        {
            Response.End();
        }
    }

Thanks for your time!谢谢你的时间!

Chrome has a built-in PDF viewer, but Internet Explorer does not. Chrome 有一个内置的 PDF 查看器,但 Internet Explorer 没有。 Do you have an external PDF viewer (ie, Adobe Acrobat or Adobe Reader) installed and configured for web view?您是否为 web 视图安装和配置了外部 PDF 查看器(即 Adobe Acrobat 或 Adobe Reader)?

Sorry, no rep, can't post comments.对不起,没有代表,不能发表评论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM