Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenate PDFs and preserve Extended Features in Acrobat Reader

Tags:

pdf

acrobat

itext

We are using iText to automatically fill in form fields on a number of documents and then concatenating those documents into one resulting PDF.

Adobe has introduced the Extend Features in Acrobat Reader option to allow users of Acrobat Reader to save the PDF with changes to the form fields.

This is a proprietary Adobe feature that iText can only work around.

I have been able to execute the work around for one specific document using the PdfStamper class in append mode. Since the PDF's contain form fields, we use the PdfCopyFields class to perform the concatenation. PdfCopyFields does not have an append mode.

Is there another way to do an append of a PDF into a preexisting PDF with iText (any version)?

like image 791
Tom Hubbard Avatar asked Jan 05 '11 17:01

Tom Hubbard


1 Answers

It's possible, but would require you to know enough to modify PdfCopyFields so that it saves in append mode.

You could duplicate the functionality and use it on top of PdfStamper (in your own class or otherwise), subclass PdfCopyFields, or modify PdfCopyFields directly.

Big Stumbling Block All fields with the same name in a PDF share the same value as well. If you have two copies of the same form in your resulting PDF, then you have two views of the same data.

Even with different forms, if you happen to have a name collision ("City" over here might be part of a current address, while over there it might be the city they were born in), they'll glom together the same value.

If you have a Comprehensive System such that all your naming collisions will be deliberate, that's great, go for broke. If "FirstName" is always referring to the same person, and changing it SHOULD change the value across all the forms in question, you're golden. If not... that's why PdfStamper's flattening ability is so popular.

The alternative becomes "rename all your fields before gluing the forms together" to avoid such collisions.

Even with a Comprehensive System, I still suggest whipping up a little tool that'll go through the forms you propose to merge and look for collisions. Maybe list them along with their values in some test data. You might catch something along the lines of "Fly: House, Common" vs "Fly: Southwest Airlines".

Probably not that particular example, but who knows? ;)

like image 167
Mark Storer Avatar answered Sep 28 '22 06:09

Mark Storer