pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gilad Denneboom <gilad.denneb...@gmail.com>
Subject Re: How to trim whitespace from options in a combobox on an existing PDF form?
Date Tue, 29 Dec 2015 21:55:36 GMT
You're using a very old version of PDFBox. In later versions a method was
added to the PDChoiceField class called getOptions. You can use it to
return a COSArray with the options for that field, and then iterate through
them (trimming them as you do) and comparing them to your string. You can
also write your own method to write new options for your field, based on
the code of getOptions, which is basically just this line:

return (COSArray) getDictionary().getDictionaryObject(COSName.OPT);


On Tue, Dec 29, 2015 at 9:45 PM, Wojack, Robert (USTP) <
Robert.Wojack@usdoj.gov> wrote:

> We have a client that provides us with interactive PDF forms for our app
> to populate fields with user data.
>
> The problem is the client sometimes provides us forms with typos and is
> not responsive about fixing them. In this case, we are given a form with a
> combo box of options, and some of the options accidentally have trailing or
> leading whitespace. So when we attempt to select an option using the
> setValue(String optionValue) method, it fails to match (i.e., "Maine" fails
> to match the "Maine " option on the form).
>
> As a workaround, we can add the extraneous whitespace to induce a match
> for these occasional goofs, but of course that is extremely hacky. Is there
> a way to trim all of the whitespace from all of the option values in an
> existing PDF before attempting to set the value?
>
> We are using PDFBox 1.2.1, but we are open to upgrading to a newer version.
>
> Thanks
>
> Bob Wojack
>
>

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