简体   繁体   English

如何使用Java PDFBOX api检查PDF格式的复选框

[英]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 如何使用Java PDFBOX api检查PDF格式的复选框

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 ? 最初我尝试使用下面的代码,但执行后复选框字段在PDF中是不可见的,但它已被检查..如何避免这种情况或他们实现的方式是错误的? 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 谢谢

Finally got it work !!!! 终于搞定了!!!! change made in setValue statment and replaced with ((PDCheckbox) feld3).check(); 在setValue语句中进行更改并替换为((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();

    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM