【问题标题】:Combining PDFs with PDFSharp losing form fields将 PDF 与 PDFSharp 丢失表单域相结合
【发布时间】:2013-02-19 18:56:47
【问题描述】:

我正在尝试使用 PDFSharp 和此代码(我找到 here)将两个创建的 PDF 文件连接到一个新的 PDF:

        // Open the output document
        PdfDocument outputDocument = new PdfDocument();
        // Iterate files
        foreach (string file in files)
        {
            // Open the document to import pages from it.
            PdfDocument inputDocument = PdfReader.Open(file, PdfDocumentOpenMode.Import);

            // Iterate pages
            int count = inputDocument.PageCount;
            for (int idx = 0; idx < count; idx++)
            {
                // Get the page from the external document...
                PdfPage page = inputDocument.Pages[idx];
                // ...and add it to the output document.
                outputDocument.AddPage(page);
            }
        }
        // Save the document...
        string filename = Path.Combine(this.tempFolder, "MyPDF.pdf");
        outputDocument.Save(filename);

第二个 PDF 包含我填写的表单域,也使用 PDFSharp。我遇到的问题是,当合并到一个新的 PDF 中时,表单字段显示为空白。

在创建并保存后,我打开了第二个 PDF,表单字段与文本一起显示得很好。

我是否遗漏了什么,或者 PDFSharp 在这个问题上是否存在某种错误?在我看来,如果我可以很好地打开和查看 PDF,那么将它们组合起来应该没有任何问题。

提前感谢您的帮助!

【问题讨论】:

  • 我还没有找到一个很好的解决方案。然而,经过多次尝试后最终奏效的是确保两个 pdfdocuments 都具有 acroform 属性,并确保“/NeedApperances”设置为 true。 returnDocument.AcroForm.Elements["/NeedAppearances"] = new PdfBoolean(true)。您也不能只添加 acroform。您可能需要使用表单初始化您的 pdfdocument 和现有 pdf。

标签: .net merge pdfsharp


【解决方案1】:

PDFsharp 不完全支持表单域。我没有对此进行检查,但是在将 PDF 文件与填充的表单字段组合时可能会出现错误。我们会继续维护和改进 PDFsharp,但没有计划改进表单域的处理。

如果您尝试不同的方式,也许它会起作用:打开第二个 PDF 进行修改,打开第一个 PDF 进行导入,然后在第二个文件的开头添加第一个文件的页面(如果两者都这样,这可能不起作用文件包含填写的表单域)。
如果您必须保留原始文件,请在执行此操作之前创建第二个文件的副本。

【讨论】:

  • 感谢您的回复。我已经尝试过您将第一页添加到第二页开头的建议,但没有任何运气。这似乎是 PDF 版本的问题:我们最终使用来自 iTextSharp 的东西解决了这个问题(请参阅this link)。但是,我现在正在使用不同的 PDF 解决同样的问题,这种解决方法似乎无法解决问题... =S
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-08
  • 1970-01-01
  • 2011-09-08
  • 2020-10-03
相关资源
最近更新 更多