What is the common way to check the check box field in a pdf using iTextsharp?

匿名 (未验证) 提交于 2019-12-03 03:12:02

问题:

I am filling the data for a fillable pdf using iTextsharp. There are n number of checkboxes in the pdf form. I have set the value for the check boxes using "Yes" or "No". This works fine. But some of the check boxes does not work in this way; instead i need to use 1 or 0 to make it work. So can anyone help me what is the common way to check/uncheck the checkboxes in pdf using iTextSharp?

Thanks in Advance,

Snowwhite

回答1:

you can find in this way:

PdfReader reader = new PdfReader(fileNameIn); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(fileNameOut)); AcroFields form = stamper.getAcroFields();  form.setField("Name","Test Name"); form.setField("odot","123456"); form.setField("Consortium","A Testing Co"); form.setField("PName","My Name"); form.setField("date","10/14/03"); form.setField("Box1","true"); //This is the checkbox control stamper.close(); 

hope this help



回答2:

Open chosen PDF and convert it.

PdfReader reader = new PdfReader(fileNameIn); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(fileNameOut)); AcroFields form = stamper.getAcroFields(); 

Inspect the form objects Fields > Keys > Results view to find the string value of a Check Box, in my case is was "Check Box1"

String[] checkboxstates = form.GetAppearanceStates("Check Box1"); 

Inspect the checkboxstates variable. [0] = value of non checked, [1] = value of checked. Then to make it checked

fields.SetField("Check Box1", "checkboxstates[1]") 


回答3:

There is no "common way". You need to know the check/uncheck values in order to change them.

There's a similar question I answered where I showed how to find out those values... Ah!

Get the export value of a checkbox using iTextSharp



回答4:

pdfFormFields.SetField("formfieldchkbox", "Yes"); pdfFormFields.SetField("formfieldchkbox", "No");

That should do the job.



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