iTextSharp-generated PDFs now cause Save dialog in Adobe Reader X

杀马特。学长 韩版系。学妹 提交于 2019-11-26 17:58:42

The problem is this line:

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

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

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

Also add

HttpContext.Current.Response.End();

After completion of your PDF file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!