c# - Completing check boxes within a PDF using iTextSharp -


i'm trying take existing pdf, find existing check boxes , complete them based on criteria using c#.

after reviewing other related questions: https://stackoverflow.com/a/4827996/6328714

the main issue having finding of checkbox objects within pdf - believe need able reference correct checkbox within code.

as tools view pdf's internal structure using pdfxplorer, i'm not having luck finding actual check boxes within tree-structure.

so:

  • do ~need~ object able check box?
  • is checking boxes simple posted code below? (it seems straight forward if so)

below example taken linked question:

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 checkbox control stamper.close(); 

the first thing want do, find fields defined form, , discover of fields check boxes.

read question find out how done: itext doesn't set checkbox field

public class mainclass {     public static void main(string[] args) {         try {             pdfreader reader = new pdfreader("pdf/fw9_template.pdf");             pdfstamper stamper = new pdfstamper(reader, new fileoutputstream("test.pdf"));             acrofields form = stamper.getacrofields();              string states[] = form.getappearancestates("topmostsubform[0].page1[0].federalclassification[0].c1_1");             system.out.println(states);               (iterator = form.getfields().keyset().iterator(); i.hasnext(); ) {                 string key = (string) i.next();                 system.out.print(key + " : ");                 switch(form.getfieldtype(key)) {                     case acrofields.field_type_checkbox:                         system.out.println("checkbox");                         break;                     case acrofields.field_type_combo:                         system.out.println("combobox");                         break;                     case acrofields.field_type_list:                         system.out.println("list");                         break;                     case acrofields.field_type_none:                         system.out.println("none");                         break;                     case acrofields.field_type_pushbutton:                         system.out.println("pushbutton");                         break;                     case acrofields.field_type_radiobutton:                         system.out.println("radiobutton");                         break;                     case acrofields.field_type_signature:                         system.out.println("signature");                         break;                     case acrofields.field_type_text:                         system.out.println("text");                         break;                     default:                         system.out.println("?");                 }             }             form.setfield("topmostsubform[0].page1[0].federalclassification[0].c1_1[0]", "true");              stamper.close();         } catch (exception e) {             system.out.println(e);         }     } } 

then want check check box, asked in question get field value check box

testform.setfield("amountcollect", "off"); testform.setfield("amountcollect", "yes"); testform.setfield("amountcollect", "0"); 

different check boxes can have different values ("on", "yes", "true", "1",...) on state (read how determine “checked” value checkboxes (from getappearancestates)), have use getappearances() method know values can used.

all of is, of course, explained in great detail on official itext web site, first place should when looking answer:

browsing official faq, you'll discover itext has tool inspect objects inside pdf. tool called rups.


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -