How to set a checkbox in a PDF form using Java PDFBOX api

How to set a checkbox in a PDF form using Java PDFBOX api

Initially, I tried using the code below, but after the “Execution” check box is invisible in PDF, but it was checked .. how to avoid such circumstances or are they, as I implemented, incorrect? can someone help me

public void check() throws Exception { PDDocument fdeb = null; fdeb = PDDocument.load( "C:\\Users\\34\\Desktop\\complaintform.pdf" ); PDAcroForm form = fdeb.getDocumentCatalog().getAcroForm(); PDField feld3 = form.getField( "check" ); feld3.setValue("check"); fdeb.save("C:\\Users\\34\\Desktop\\complaintform.pdf"); fdeb.close(); } 

thanks

+4
source share
1 answer

It finally works !!!! a change made in the setValue status and replaced with ((PDCheckbox) feld3) .check ();

 public void check() throws Exception { PDDocument fdeb = null; fdeb = PDDocument.load( "C:\\Users\\34\\Desktop\\complaintform.pdf" ); PDAcroForm form = fdeb.getDocumentCatalog().getAcroForm(); PDField feld3 = form.getField("loan"); ((PDCheckbox) feld3).check(); fdeb.save("C:\\Users\\34\\Desktop\\complaintform.pdf"); fdeb.close(); } 
+8
source

All Articles