pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Roberto Nibali <rnib...@gmail.com>
Subject Re: Fwd: Migrate form field entries from one pdf to another
Date Sun, 28 Jun 2015 20:18:41 GMT
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.

Cheers
Roberto

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message