pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Maruan Sahyoun <sahy...@fileaffairs.de>
Subject Re: Migrate form field entries from one pdf to another
Date Mon, 29 Jun 2015 05:37:31 GMT
Hi,

> Am 28.06.2015 um 22:18 schrieb Roberto Nibali <rnibali@gmail.com>:
> 
> Hi
> 
> 
>                else if (f instanceof PDCheckbox)
>>                {
>>                    fieldValue = fieldValues.get(fieldName);
>> 
> 
> How is this supposed to work? The value one gets via getValue() from the
> PDField is always null for PDCheckboxes.
> 
> 
>>                    if (("TRUE".equalsIgnoreCase(fieldValue))
>>                            || ("CHECKED".equalsIgnoreCase(fieldValue))
>>                            || ("YES".equalsIgnoreCase(fieldValue)))
>>                    {
>>                        ((PDCheckbox) f).check();
>>                    }
>>                    else
>>                    {
>>                        ((PDCheckbox) f).unCheck();
>>                    }
>>                }
>> 
> 
> 
> Here is some code I use to verify the above statement:
> 
> private void analyseAndPrintFields(PDField field) throws IOException {
>    String fqName = field.getFullyQualifiedName();
>    String value = (field.getValue() != null ? field.getValue() : "_n/a_");
> 
>    if (field instanceof PDCheckbox) {
>        PDCheckbox checkbox = (PDCheckbox) field;
>        logerr("DEBUG: Checkbox [" + fqName + "]:  On=" +
> checkbox.getOnValue() +
>                " Off=" + checkbox.getOffValue() +
>                " Checked=" + (checkbox.isChecked() ? "true" : "false") +
>                " Value=" + value);
>        //TODO: Check if widgets handling is necessary: checkbox.getWidget();
>    } else if (field instanceof PDRadioCollection) {
>        PDRadioCollection collection = (PDRadioCollection) field;
>        logerr("DEBUG: RadioButtons [" + fqName + "]: " +
> collection.getValue() + " Value=" + value);
>    } else if (field instanceof PDPushButton) {
>        PDPushButton button = (PDPushButton) field;
>        logerr("DEBUG: Pushbuttons [" + fqName + "]: " +
>                        "Export/Readonly/Required=" +
>                        button.isNoExport() + "/" +
>                        button.isReadonly() + "/" +
>                        button.isRequired() +
>                        " Value=" + value
>        );
>    }
> }
> 
> Running this particular code inside my loading part, reveals the following
> output for any given PDF:
> 
> DEBUG: Checkbox [01.011.hkanrede]:  On=Frau Off=Off Checked=false
> Value=_n/a_
> DEBUG: Checkbox [01.011.hkanrede]:  On=0 Off=Off Checked=true Value=_n/a_
> DEBUG: Checkbox [01.011.hksprache]:  On=0 Off=Off Checked=true Value=_n/a_
> DEBUG: Checkbox [01.011.hksprache]:  On=1 Off=Off Checked=false Value=_n/a_
> DEBUG: Checkbox [01.011.hksprache]:  On=2 Off=Off Checked=false Value=_n/a_
> DEBUG: Checkbox [01.011.hksprache]:  On=3 Off=Off Checked=false Value=_n/a_
> 
> I have the distinct feeling that I am completely missing the point here.
> The abstraction level of the PDFBox library should actually deal with this,
> so the user does not have to, right? Although, you do have getOnValue() and
> getOffValue() for example when it comes to PDCheckBox type fields.


getValue and getOnValue/getOffValue return different settings of the field. getValue works
on the field dictionaries 'V' entry whereas getOnValue/getOffValue look at the fields appearance
settings.

Normally when a checkbox is checked the fields value AND the appearance need to be updated.
This is not the case with your form. How was the value of the original form set? Which software?

BR
Maruan


> 
> Cheers
> Roberto


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Mime
View raw message