We are currently using the old iText 2.1.7 version but are evaluating itextpdf 5.5.0.
We have PDF forms created in Libreoffice and also in Quartz (on Mac).
There are no problems whatsoever when filling out the forms in 2.1.7 (Stamper/setField etc.).
With 5.5.0 however the forms made in Quartz work fine, but the forms made in Libreoffice do not.
Basically: With FormFlattening(false) the data appears in the final document(as well as the fields), but with FormFlattening(true) the data (and the fields) are empty.
The main difference I see between the LibreOffice and Quartz PDF is that all fonts are embedded in the Quartz generated PDF. This is not possible with LibreOffice.
Could this be the problem? And if so, why does 2.1.7 work?
Thanks in advance,
Snorri

- 3
- 3
-
Are you testing this on your machine or on a production server? I don't know much about iText, but once I had problems with fonts on the production server, because iText searches for fonts installed on the operation system. It only has a few fonts embedded in their jars. – rcarraretto Jun 12 '14 at 11:47
-
Thank you for your comment, but mkl's answer did the trick. – user3733812 Jun 12 '14 at 13:50
1 Answers
Basically: With FormFlattening(false) the data appears in the final document(as well as the fields), but with FormFlattening(true) the data (and the fields) are empty.
If af
is your AcroFields
instance, try to do
af.setGenerateAppearances(true);
before closing the stamper.
The PDF specification ISO 32000-1 defines a NeedAppearances flag, cf. Table 218 – Entries in the interactive form dictionary. If it is set to true, a PDF viewer knows that it has to create appearance streams for form fields.
Old iText versions ignored that flag completely and always created appearance streams during form fill-in. Newer iText versions respect that flag and only create appearance streams while filling in forms if the flag is not true (in the other case the viewer will re-create such appearances anyways).
When flattening forms, iText simply embeds the appearances of the form elements into the page content. If no appearance stream was created for some field during fill-in, therefore, the value will not appear in the flattened document.
Using setGenerateAppearances(true)
you can enforce appearance stream generation.

- 90,588
- 15
- 125
- 265
-
1some time has passed since this solution but u helped me after many hours of research, ty so much :D – tom3008 May 21 '16 at 18:20