Question
Is there a way in iText to copy just the PDF acroform fields from one PDF document to another PDF document? I have the code to copy the entire PDF, but I would like to be able to overlay all my fields to a new/updated PDF document.
Solution
public void replaceBackground(String newBackground, String CurrentForm, String newFile) throws Exception
{
PdfReader reader = new PdfReader(newBackground);
PdfReader reader2 = new PdfReader(CurrentForm);
PdfStamper stamp = new PdfStamper(reader2, new FileOutputStream(newFile));
stamp.replacePage(reader, 1, 1);
stamp.close();
}
OTHER TIPS
I don't quite remember very well if we were able to achieve this since I was not directly working on the implementation but I remember pointing someone in this direction a while ago.
You may use the PdfStamper to extract fields out of the acroForm and then use the PdfWriter to create a new AcroForm with the pre-populated fields. I wish I could give you a better example but I don't quite have the code with me.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow