【发布时间】: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。