Reputation: 2687
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
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):
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:
This is the iText 5 answer; the other answer was an iText 7 answer.
Upvotes: 1
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