pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Wojack, Robert (USTP)" <Robert.Woj...@usdoj.gov>
Subject RE: How to trim whitespace from options in a combobox on an existing PDF form?
Date Thu, 31 Dec 2015 16:04:51 GMT
Hi Gilad,

Thanks for your prompt response. It seems as though the const, COSName.OPT, is not available
in PDFBox 1.2, so I assume that we would still need to upgrade to PDFBox 1.8 even to roll
our own getOptions(), correct?

Bob Wojack
SRA International, Inc.
Onsite Contractor for the Department of Justice
Senior Tech Lead
US Trustee Program
Onsite Email Address:     Robert.Wojack@usdoj.gov
Onsite Phone Number:    TBD
Cell#:			   (301)910-9975

-----Original Message-----
From: Gilad Denneboom [mailto:gilad.denneboom@gmail.com] 
Sent: Tuesday, December 29, 2015 4:56 PM
To: users@pdfbox.apache.org
Subject: Re: How to trim whitespace from options in a combobox on an existing PDF form?

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
View raw message