S.Serem
S.Serem

Reputation: 101

Java PDFBox does not maintain the font appearence of a field if it appears severraly in a PDF Form

I need to fill a pdf form dynamically from my java web app and I found PDFBox to be really useful except for an issue or challenge am facing when I have multiple fields with same name.

I have 5 fields with same name(lets say 'wcode') in different places on a one page pdf form. This fields have different fonts. Normally when you fill out one field manually the other fields automatically pick the sames value, the same this happens when I fill it using PDFbox except that PDFBox changes all my 5 fields to have same font as the first field to appear in the pdf form.

Here is the code used to fill the field.

PDDocument _pdfDocument = PDDocument.load(new File(originalPdf))
PDAcroForm acroForm = _pdfDocument.getDocumentCatalog().getAcroForm();    
PDTextField myCodeField = (PDTextField) acroForm.getField("wcode");
       if (myCodeField != null) {
          myCodeField .setValue(my.getCode());
       }
//Refresh layout && Flatten the document                
       acroForm.refreshAppearances();
       acroForm.flatten();
 _pdfDocument.save(outputFile);

I added

acroForm.refreshAppearances();

after some research but that did not change anything.

So if the first 'wcode' field to appear on the pdf form is 6pt all the other 'wcode' fields in the rest the pdf will be 6pt even if I had set them in appearance properties to 12pt.

I am using PDFBox 2.0.5

Upvotes: 0

Views: 554

Answers (1)

S.Serem
S.Serem

Reputation: 101

The issue has been resolved in version PDFBox 2.0.6 released about a month ago. Check comment on the jira 3837 here

Upvotes: 1

Related Questions