I have two PDF forms – an orignial form and a new form. The new form has x amount of extra acro fields on it, however it doesn’t have the original PDF fields.
I want to merge the fields from the old PDF to the new PDF form. The new field/fields would of moved some of the placeholders for the old fields so they may overlap or not be in the correct place, but this is irrelevant.
What I have tried
//Get the old PDF
PdfReader oldPdfReader = new PdfReader("Old.Pdf");
MemoryStream oldMs = new MemoryStream();
PdfStamper oldPdfStamper = new PdfStamper(oldPdfReader, oldMs);
//Get the new PDF
PdfReader newPdfReader = new PdfReader("New.Pdf");
MemoryStream newMs = new MemoryStream();
PdfStamper newPdfStamper = new PdfStamper(newPdfReader, newMs);
foreach(var oldField in oldPdfStamper.AcroFields.Fields)
{
//Do a check to see if the field isn't already added
if(!newPdfStamper.AcroFields.Fields.Any(x => x.Key == oldField.Key))
newPdfStamper.AcroFields.Fields.Add(oldField);
}
This only outputs the new fields even though the debug hits the add, I have concluded this isn’t correct and I need to draw the fields on some how.
I have also tried the following example:
Merging multiple PDFs using iTextSharp in c#.net
It puts the new field on from New.PDF but doesn’t carry over the fields from Old.PDF. Any ideas on how I can merge the AcroFields from two PDF forms?
1 Answer