我的应用程序正在使用 itext# 生成 PDF 文档。文件可以正常打开并在 Foxit Reader 中正确显示,但在 Adobe Acrobat 中会出现以下错误:
There was an error processing page. There was a problem reading this document (109).
为什么文件会在一个文件中打开而不是另一个文件?
最佳答案
这是我的代码:
var document = new Document(_pageSize, PageMargin, PageMargin, PageMargin, PageMargin);
var writer = PdfWriter.GetInstance(document, output);
writer.CloseStream = false;
writer.PageEvent = new Footer(HeaderFont, _defaultFont.BaseFont, report.Name);
document.Open();
if (report.Results.Any())
document.Add(CreateTable(report.Results, report.Types, report.RootType));
else
document.Add(new Paragraph("No results", _defaultFont));
writer.Close();
在 writer.Close();
行之前添加 document.Close();
行后,它现在同时显示在 Foxit 中和 Acrobat。
我想 itext# 的关键是要非常小心地正确关闭对象。这可能反射(reflect)了它是一个移植库,而不是从头开始为 .NET 构建的库。
关于使用 itext# 生成的 PDF 文档在 Foxit 中打开,而不是在 Acrobat 中打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4140623/