PDF文件不显示在Internet Explorer中了 [英] pdf file not showing up in Internet explorer

查看:952
本文介绍了PDF文件不显示在Internet Explorer中了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

语言:ASP.NET/VB.NET

我使用iTextSharp的库创建PDF文件。在我的机器生成的文件都没有任何问题的开放。但是,当我上传的生产服务器,IE浏览器只需打开在编译的程序,并关闭窗口,但不显示PDF文件。其它浏览器都出现了PDF文件。

下面是code我使用

 昏暗LABNO为整数=的Request.QueryString(LABNO)
        昏暗VDOC作为新iTextSharp.text.Document(PageSize.A4,20,20,50,50)        昏暗VOUTPUT作为新IO.MemoryStream
        昏暗vWriter = pdf.PdfWriter.GetInstance(VDOC,VOUTPUT)
        昏暗的CB作为新PdfContentByte(vWriter)
        MakeReceipt(LABNO,VDOC,CB)
        vDoc.NewPage()
        MakeReceipt(LABNO,VDOC,CB)
        MakeSheet(LABNO)
        vDoc.Close()        DIM RND作为新的随机
        Response.Clear()
        Response.ClearContent()
        Response.ClearHeaders()        Response.ContentType =应用程序/ PDF
        Response.AddHeader(内容处置的String.Format(附件;文件名= Rct- {0} .PDF,rnd.Next.ToString()))
        Response.BinaryWrite(vOutPut.ToArray())
        Response.Flush()


解决方案

这个问题(由于道路MSIE接受字节)在的iText在行动的书解释。您可以通过添加额外的头解决这个问题:的Content-Length (该值是VOUTPUT字节数

为什么会出现这种问题的发生?如果你不告诉MSIE多少字节期望,它会下载一个特定的大小(以时间,例如1028字节)的块。如果您的PDF的大小不是这样大小的整数倍,那么多余的(垃圾)字符将在最后补充道。某些PDF查看器无法处理这些额外的字符。

根据经验,我还添加以下标题:

 过期,0
缓存控制,必须重新验证,检查后= 0,pre-检查= 0
语法,公共

我不知道自己是否真的有必要,但他们没有受到伤害。

Language : ASP.NET/VB.NET

I am creating pdf file using itextsharp library. On my development machine generated files are opening up without any problem. But when I upload the compiled program on production server, internet explorer just open and close the window but does not show the pdf file. Other browsers are showing up the pdf file.

Here is the code I am using

        Dim LABNO As Integer = Request.QueryString("LABNO")
        Dim vDoc As New iTextSharp.text.Document(PageSize.A4, 20, 20, 50, 50)

        Dim vOutPut As New IO.MemoryStream
        Dim vWriter = pdf.PdfWriter.GetInstance(vDoc, vOutPut)
        Dim cb As New PdfContentByte(vWriter)
        MakeReceipt(LABNO, vDoc, cb)
        vDoc.NewPage()
        MakeReceipt(LABNO, vDoc, cb)
        'MakeSheet(LABNO)
        vDoc.Close()

        Dim rnd As New Random
        Response.Clear()
        Response.ClearContent()
        Response.ClearHeaders()

        Response.ContentType = "Application/pdf"
        Response.AddHeader("Content-Disposition", String.Format("attachment;filename=Rct-{0}.pdf", rnd.Next.ToString()))
        Response.BinaryWrite(vOutPut.ToArray())
        Response.Flush()

解决方案

This problem (due to the way MSIE accepts bytes) is explained in the "iText in Action" books. You can solve it by adding an extra header: Content-Length (the value is the number of bytes in vOutPut.

Why does this problem occur? If you don't tell MSIE how many bytes to expect, it will download blocks of a specific size (e.g. 1028 bytes at a time). If the size of your PDF isn't an exact multiple of this size, then extra (garbage) characters will be added at the end. Some PDF viewers can't deal with these extra characters.

Based on experience I also add the following headers:

"Expires", "0"
"Cache-Control", "must-revalidate, post-check=0, pre-check=0"
"Pragma", "public"

I don't know if they are really necessary, but they don't hurt.

这篇关于PDF文件不显示在Internet Explorer中了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆