我正在尝试使用 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,那么合并它们应该没有任何问题。
在此先感谢您的帮助!
最佳答案
PDFsharp 不完全支持表单域。我没有检查这个,但是在将 PDF 文件与填充的表单字段组合时可能会出现错误。我们继续维护和改进 PDFsharp,但没有计划改进表单域的处理。
如果您尝试不同的方式,也许它会起作用:打开第二个 PDF 进行修改,打开第一个进行导入,然后在第二个文件的开头添加第一个文件的页面(如果两个文件都包含填充表单域)。
如果必须保留原始文件,请在执行此操作之前创建第二个文件的副本。
关于.net - 将 PDF 与 PDFSharp 丢失表单字段相结合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14965242/