copy pdf form with PdfCopy not working in itextsharp 5.4.5.0

烈酒焚心 提交于 2019-11-28 01:23:54

There are several issues here.

1) You have to enable form field merging for PdfCopy:

// ...
var copy = new PdfCopy(document, outputPdfStream);
copy.SetMergeFields();
document.Open();
// ...

This works for iText 5.4.5 (Java), but for iTextSharp Reader/Acrobat complain about an embedded font when displaying page 2 of the merged document. This is probably a porting issue.

2) EV_Original.pdf doesn't have appearances ("visualizations") for the form fields. Instead it has the NeedAppearances flag set. This indicates the PDF viewer needs to generate appearances when displaying the document.

PdfCopy doesn't process NeedAppearances correctly at the moment, so it isn't set in the output document. This needs to be fixed in iText. As a workaround, you could set NeedAppearances on your output document after merging:

PdfReader postreader = new PdfReader("combined4.pdf");
PdfStamper poststamper = new PdfStamper(postreader, new FileStream("combined4-needappearances.pdf", FileMode.Create));
poststamper.AcroFields.GenerateAppearances = true;
poststamper.Close();

But taking into account the porting bug in iTextSharp 5.4.5, I'd suggest to use PdfCopyFields until PdfCopy is fixed in the next release. Memory usage for PdfCopyFields and PdfCopy are similar when merging Acroforms. This is inherent to Acroform merging: more information need to be kept in memory. That's why it has to be explicitly enabled in PdfCopy using SetMergeFields().

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!