What is the general way to check the checkbox field in pdf using iTextsharp?

I populate data for populated pdf using iTextsharp. There are n flags in pdf format. I set the value for the checkboxes using Yes or No. It works great. But some of these flags do not work this way; instead, I need to use 1 or 0 to make it work. So can someone help me what is a common way to check / uncheck pdf checkboxes using iTextSharp?

Thanks Advance,

Snowwhite

+4
source share
4 answers

you can find as follows:

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

+7
source

Open the selected PDF and convert it.

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

Inspect the objects of the form Fields> Keys> View results to find the string value of the flag, in my case it is "Check Box1"

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

Check the checkboxstates variable. [0] = value not verified, [1] = value verified. Then to check it out

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

There is no "common path". To change them, you need to know the check / uncheck values.

There was a similar question to which I answered, where I showed how to find out these values ​​... Ah!

Get checkbox export value using iTextSharp

+3
source

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

That should do the job.

+1
source

Source: https://habr.com/ru/post/1337463/


All Articles