> can i ignore the creators string assignments by 
> simply checking if the checkbox is *checked* so i can assign 
> my own values like "true" and "false"?

The "on" value may change at the whim of the PDF creator, but the "off" value 
does not.  So work with that:

value = acroFields.getField(key)/*.toString()*/;// getField() returns a String, 
toString() is redundant, redundant and redundant.

if (acroFields.getFieldType(key) == AcroFields.FIELD_TYPE_CHECKBOX) {
  // I'm reasonably confident that case sensitivity here is okay.
  value = ("Off".equals(value) ? "false" : "true");
}

fieldsHashMapStrings.put(key, value);

This code ignores a null "value" (which becomes "true", almost certainly not 
what you want), but I think you get the idea.

--Mark Storer
  Senior Software Engineer
  Cardiff.com
 
import legalese.Disclaimer;
Disclaimer<Cardiff> DisCard = null;
 
 

> -----Original Message-----
> From: [email protected] [mailto:[email protected]] 
> Sent: Monday, November 15, 2010 5:53 AM
> To: [email protected]
> Subject: [iText-questions] how to find if a checkbox is 
> checked (NOT get thevalue)
> 
> 
> 
>  hi,
> 
> i get pdf-forms from an external source and have to transform 
> the forms to a xml format (fieldname -> value) which up to 
> now was no problem.
> but the crators of the pdf-forms do an inconsistent job with 
> assigning string values to pdf- checkboxes...
> often getAppearanceStates is [0] -> "Ja", [1] -> "Off" but 
> sometimes its [0] -> "", [1] -> "Off" so every type of 
> questionaire pdf would have to be checked for irregulatitys 
> on all checkbox states before converting into xml.... :/ 
> question is: can i ignore the creators string assignments by 
> simply checking if the checkbox is *checked* so i can assign 
> my own values like "true" and "false"?
> 
> # little code to see if a field is a checkbox and # the 
> creators assigned values for checked and undchecked
> 
>     public boolean ParsePDF() {
>         fieldsHashMapStrings = new HashMap();
>         AcroFields acroFields = pdfReader.getAcroFields();
>         HashMap<String, Item> fieldsHashMap = acroFields.getFields();
>         for (Iterator i = fieldsHashMap.keySet().iterator(); 
> i.hasNext();) {
>             String key = i.next().toString();
>             String value = "";
>             if (acroFields.getField(key) != null) {
>                 if (acroFields.getFieldType(key) ==
> AcroFields.FIELD_TYPE_CHECKBOX) {
>                     System.out.println(key + " is checkbox");
>                     String[] appearanceStates = 
> acroFields.getAppearanceStates(key);
>                     for (int j = 0; j < 
> appearanceStates.length; j++) {
>                         String string = appearanceStates[j];
>                         System.out.println(j+"->"+string);
>                     }
>                 } else {
>                     value = acroFields.getField(key).toString();
>                 }
>             }
>             fieldsHashMapStrings.put(key, value);
>         }
>         return true;
>     }
> 
> # sample output
> 
> ...
> GefB_ang is checkbox
> 0->Ja
> 1->Off
> AnfProfil_Z_nein is checkbox
> 0->Ja
> 1->Off
> Sibe_intern is checkbox
> 0->                              ############ HERE the ARGH!
> 1->Off
> PSA_nein is checkbox
> 0->Ja
> 1->Off
> ....
> 
> 
> Mit freundlichen Grüßen
> Christoph Mikusch
> 
> Berufsgenossenschaft Nahrungsmittel und Gaststätten 
> Dynamostraße 7 - 11
> 68165 Mannheim
>                                                         
>  Telefon:  +49 (0) 621 4456-3127                        
>                                                         
>  Mail:     [email protected]                     
>                                                         
>  Internet: www.bgn.de                                   
>                                                         
> 
> 
> 
> 
> 
> --------------------------------------------------------------
> ----------------
> Centralized Desktop Delivery: Dell and VMware Reference 
> Architecture Simplifying enterprise desktop deployment and 
> management using Dell EqualLogic storage and VMware View: A 
> highly scalable, end-to-end client virtualization framework. 
> Read more!
> http://p.sf.net/sfu/dell-eql-dev2dev
> _______________________________________________
> iText-questions mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/itext-questions
> 
> Many questions posted to this list can (and will) be answered 
> with a reference to the iText book: 
> http://www.itextpdf.com/book/ Please check the keywords list 
> before you ask for examples: http://itextpdf.com/themes/keywords.php
> 
> 

------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to