saravana_pc
saravana_pc

Reputation: 2687

Set visible property of fields in a PDF

I have a PDF template file with a button field on it. Let's say, the name of the button field in "Button1". Is it possible to hide this button from my java application using iText (v5.5)?

Upvotes: 0

Views: 2277

Answers (2)

Bruno Lowagie
Bruno Lowagie

Reputation: 77528

Please take a look at the HideButton example. In this example, we take a PDF named hello_button.java that has a button named "Test" (the gray area in the screen shot):

enter image description here

The field with name "Text" corresponds with one widget annotation. We can change the flags of this annotation like this:

PdfReader reader = new PdfReader(src);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
AcroFields form = stamper.getAcroFields();
form.setFieldProperty("Test", "setflags", PdfAnnotation.FLAGS_HIDDEN, null);
stamper.close();

The result of this operation is a file named hello_button_hidden.pdf:

enter image description here

This is the iText 5 answer; the other answer was an iText 7 answer.

Upvotes: 1

Amber
Amber

Reputation: 2463

See PDFFormField.setVisibility(int visibility) and PDFAcroForm.getField(String fieldName)

Your code will look something like this:

pdfAcroform.getField("Button1").setVisibility(PDFFormField.HIDDEN);

Upvotes: 1

Related Questions