pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Roberto Nibali <rnib...@gmail.com>
Subject Re: Migrate form field entries from one pdf to another
Date Mon, 29 Jun 2015 09:50:59 GMT
G'day

On Mon, Jun 29, 2015 at 7:37 AM, Maruan Sahyoun <sahyoun@fileaffairs.de>
wrote:

> 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.
>

This explains the code in PDFBox, thanks. Unfortunately, within two days, I
suspect I can't really understand the PDF standard to the degree necessary
to pose intelligent questions.


> 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?
>

The value set in the form is by simply clicking it in Adobe Acrobat
(Reader). It sets the field accordingly, nevertheless for a set field,
getValue() still returns null. The forms themselves were created with
InDesign, I think. Not sure though. So, you're kind of implying that
independent of the field type (Textbox, PrintButton, Checkbox,
Radiobutton), PDFBox would normally expect the value of a field to be !null?

How could I deal with this? Because this is exactly what seems to fail and
also cause this dreaded exception message when trying to fill out the forms
with anything other than PDTextbox.

Would anybody here be willing to have a Skype or Teamviewer session with me
tonight or tomorrow night to have a look at the problem? We're willing to
pay for such support. If so, please send a private message to me, so we
don't clutter this mailing list.

Best regards
Roberto

ps.: I didn't expect PDF to be so intricately complex ... it hides well
behind the tools which just seem to always work in conjunction with PDF.

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