PDF-Form Text hidden unless clicked

codejitsu picture codejitsu · Aug 30, 2012 · Viewed 16.7k times · Source

In my application I have to fill a predefined PDF form with data from DB. We are using Java and Pdfbox. The filling itself is not a problem.

The problem is that in resulting PDF-file all texts in the form are invisible (or hidden, also grey rectangles) unless field clicked.

How can I solve this problem?

Answer

dirkk picture dirkk · Jan 5, 2016

I had the same problem when I tried to programmatically fill PDF forms using pdfbox. I add this answer to a rather old question as all the other answers manipulate the original PDF, which is not always an option.

The problem with invisible form fields just appeared in Acrobat PDF, other PDF renderers showed it fine. If using pdfbox 1.8.x you have to set Need Appearances as explained here:

PDAcroForm form = docCatalog.getAcroForm();
form.getDictionary().setItem(COSName.getPDFName("NeedAppearances"), COSBoolean.TRUE);

If using pdfbox 2 this is simplified to:

PDAcroForm form = docCatalog.getAcroForm();
form.setNeedAppearances(true);