【问题标题】:PDF document generated using itext# opens in Foxit but not Acrobat使用 itext# 生成的 PDF 文档在 Foxit 中打开,而不是在 Acrobat 中打开
【发布时间】:2011-05-07 15:19:45
【问题描述】:

我的应用程序正在使用 itext# 生成 PDF 文档。文件可以正常打开并在 Foxit Reader 中正确显示,但在 Adobe Acrobat 中会出现以下错误:

There was an error processing page. There was a problem reading this document (109).

为什么文件会在一个打开而不是另一个?

【问题讨论】:

  • 此外,除了在 Acrobat Reader 中打开文档时出现上述消息外,Internet Explorer Acrobat Reader 加载项/扩展查看器在从服务器请求相关 PDF 时默认打开,会给出我收到以下消息(Local\ 后的代码有时会更改):对象标签格式错误。本地\EWH-1884-0

标签: pdf itextsharp acrobat foxit


【解决方案1】:

一些 pdf 阅读器在各个方面都比其他阅读器更宽容。 Foxit 可能会忽略它不支持的 pdf 中的位。不同版本的杂技演员在不同的事情上窒息,只是为了搅浑水。在没有看到相关 PDF 的情况下,我们只能猜测。

【讨论】:

    【解决方案2】:

    这是我的代码:

            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(); 后,它现在显示在FoxitAcrobat 中。

    我想 itext# 的一个关键是要非常小心地正确关闭对象。这可能反映了它是一个移植库,而不是从头开始为 .NET 构建的库。

    【讨论】:

    • 在 writer.Close() 之前添加行 document.Close() 导致程序崩溃。 writer.Close() 期望文档仍然可用。
    • 与 itext 书中的所有示例一样,使用 Document.close()。不需要 PdfWriter.close(),并导致生成的 pdf 损坏。
    • 在我的情况下,我将 Document 和 PdfWriter 都包装在 子句中 - 我觉得某种 Close 可能会与隐式 Dispose 一起被调用,作为 的结果,on PdfWriter - 我摆脱了 并将对 Document 和 PdfWriter 的显式调用移至 Dispose 以最终阻止 - 由于这个线程,问题得到了解决
    • 当我删除 writer.close() 时它起作用了。谢谢它的帮助!
    猜你喜欢
    • 2012-05-12
    • 2013-04-04
    • 1970-01-01
    • 2013-11-29
    • 2020-07-05
    • 1970-01-01
    • 2010-10-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多