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

﹥>﹥吖頭↗ 提交于 2019-12-07 10:58:44

问题


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


回答1:


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();

    }


来源:https://stackoverflow.com/questions/14602821/how-to-check-a-check-box-in-pdf-form-using-java-pdfbox-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!