如何使用Java PDFBOX API选中PDF表单中的复选框 [英] How to check a check box in PDF-form using Java PDFBOX api
本文介绍了如何使用Java PDFBOX API选中PDF表单中的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用Java PDFBOX API选中PDF格式的复选框
How to check a check box in PDF-form using 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 ? 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();
}
谢谢
推荐答案
终于成功了!!! 在setValue语句中进行的更改,并替换为((PDCheckbox)feld3).check();
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();
}
这篇关于如何使用Java PDFBOX API选中PDF表单中的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文