【发布时间】:2015-07-04 10:10:33
【问题描述】:
我正在使用 iTextSharp 将多页 AcroForm 拆分为单页 AcroForm,但我无法“保留”表单的完整功能:
这是我正在使用的代码:
using (PdfReader reader = new PdfReader(options.InputFile))
{
string basename = Path.GetFileNameWithoutExtension(options.InputFile);
for (int pagenumber = 1; pagenumber <= reader.NumberOfPages; pagenumber++)
{
string filename;
Document document;
PdfCopy copy;
document = new Document();
filename = String.Format("{0}.{1}.pdf", basename, pagenumber);
copy = new PdfCopy(document, new FileStream(filename, FileMode.Create));
document.Open();
copy.AddPage(copy.GetImportedPage(reader, pagenumber));
document.Close();
}
return reader.NumberOfPages;
}
生成的 pdf 页面表现得像完全正常工作的 AcroForm(当通过 Acrobat Reader 使用时)但如果我尝试通过 iTextSharp “列出”每个字段中的字段,我找不到单个字段...
附:我找到了一个“正确”拆分表格的在线服务。许多软件(例如 PDF Split and Merge Basic)的行为与我的一样。
我哪里错了?
最好的问候, 迈克
【问题讨论】:
-
我发现了一些对
CopyAcroForm和CopyDocumentFields的引用,但它们与整个文档相关,因此无法在单个页面上调用。 -
您需要使用
setMergeFields()方法,如下例所示:itextpdf.com/sandbox/acroforms/MergeForms
标签: c# pdf itextsharp