0

I am working on a project that should read a pdf file/form that contains value filled up by a Java code.

form.setField("permitnumber", p.getApplicationorno());
            form.setField("amountpaid", p.getAmount_app());
            form.setField("estimatedfeet", "56");
            form.setField("receiptnumber", "123415");
            form.setField("validity", "5");

Now my problem is, the values that were set on the fields of the pdf form worked perfectly on Adobe PDF Reader but not on the ICEPdf Viewer. What I am missing here? Why is it that the values from PDF form can't be displayed by ICEPdf?

mkl
  • 90,588
  • 15
  • 125
  • 265
silent_coder14
  • 583
  • 2
  • 10
  • 38
  • 1
    Which PDF library did you use to fill in the values? Can you share a sample PDF? – mkl Feb 24 '15 at 05:10
  • i am using iText to fill in the values in the PDF... – silent_coder14 Mar 05 '15 at 23:25
  • Depending on the source document and your code iText does or does not create form field appearances. What's your mileage? – mkl Mar 05 '15 at 23:38
  • i created the document from OpenOffice Draw application... exported as Interactive PDF... and the code to fill in the values is mentioned in the question: form.setField("fieldname", "value"); – silent_coder14 Mar 07 '15 at 10:31
  • Ooo has a history of creating PDFs with **NeedsAppearances** set to true. Can you provide a sample PDF? – mkl Mar 07 '15 at 11:25

1 Answers1

0

While setting the field values using iText, If af is your AcroFields instance, try to do

af.setGenerateAppearances(true);

before setting values.


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.

iText interprets that flag and only creates appearance streams while filling in forms if the flag is not true (if true, the viewer is expected to re-create such appearances anyways).

Ooo at least used to create PDF forms with that flag set to true. Adobe Reader does respect the flag and creates appearances if true. Probably your PDF viewer does not respect the flag, probably it always expects appearances to already exist in documents.

Using setGenerateAppearances(true) you can enforce appearance stream generation. If the above assumption is correct, this should fix your problem.

mkl
  • 90,588
  • 15
  • 125
  • 265