Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check a check box in PDF-form using Java PDFBOX api

How to check a check box in PDF-form using Java PDFBOX api

Initially I tried with the below piece of code but after the execution check box field is invisible in PDF , but it has been checked.. how to avoid such circumstances or they way i have implemented is wrong ? can any one help me out

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

like image 535
Ganeshja Avatar asked Jan 15 '23 08:01

Ganeshja


1 Answers

Finally got it work !!!! change made in setValue statment 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();

    }
like image 150
Ganeshja Avatar answered Jan 31 '23 00:01

Ganeshja