tags:

views:

895

answers:

3

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.

+1  A: 

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.

Deep Kapadia
thanks, i am delving into the details of the stamper.
Milhous
Milhous, could you please post a solution if you were able to figure it out. I am curious to know as well.
Deep Kapadia
+1  A: 
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();
     }
Milhous
A: 

I used replacePage, but found sometime it doesn't work well. If two pdf are not the same in size, some field may be omitted.

Do you have better solution (Is there a way to specify the position of replace-pdf)?

Patrick Z