iTextSharp生成的PDF现在导致Adobe Reader X中的“保存”对话框 [英] iTextSharp-generated PDFs now cause Save dialog in Adobe Reader X

查看:249
本文介绍了iTextSharp生成的PDF现在导致Adobe Reader X中的“保存”对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直使用iTextSharp生成PDF文档超过一年。不幸的是,随着Adobe Reader X的发布,我的PDF现在会导致你想保存吗?关闭PDF文档时出现的对话框。对于未使用iTextSharp生成的PDF,不会发生这种情况。对于那些整天打开和关闭PDF文档的用户来说,这真的很烦人。我可以设置iTextSharp中的任何属性以防止这种情况发生吗?

I have been using iTextSharp to generate PDF documents for over a year. Unfortunately, with the release of Adobe Reader X, my PDFs now cause a "Do you want to Save?" dialog to appear when closing the PDF document. This does not happen with PDFs that are not generated with iTextSharp. It's really annoying for my users who are opening and closing PDF documents all day long. Are there any properties in iTextSharp that I can set to prevent this from happening?

如果有帮助,我使用PdfReader从现有PDF文档中读取数据(这原始文档不会导致出现保存对话框)。然后我使用PdfWriter创建一个新文档,并使用AddTemplate将原始文档的一部分复制到新文档。

If it helps, I am using a PdfReader to read data from an existing PDF document (this original document does not cause the Save dialog to appear). I then use a PdfWriter to create a new document and AddTemplate to copy a portion of the original document to the new one.

推荐答案

问题是这一行:

Response.OutputStream.Write(MS.GetBuffer(), 0, MS.GetBuffer().Length)

GetBuffer方法返回的整个内部缓冲区大于实际内容。坏PDF在末尾有大约10kb的垃圾内容(字节为零),好的PDF只有几个垃圾字节。使用内存流的ToArray()方法获取PDF文件,问题将得到解决。您还将获得较小的文件。

The GetBuffer method returns the entire internal buffer which is larger that the actual content. The bad PDF has about 10kb of garbage content at the end (bytes of zero), the good PDF has only a few garbage bytes. Use the ToArray() method of the memory stream to get the PDF file and the problem will be fixed. You will also get smaller files.

byte[] pdf = MS.ToArray();
Response.OutputStream.Write(pdf, 0, pdf.Length);

同时使用pdf数组的长度设置Content-Length。

Also set the "Content-Length" with the length of the pdf array.

这篇关于iTextSharp生成的PDF现在导致Adobe Reader X中的“保存”对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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