pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kevin Ternes <KTer...@thegeneral.com>
Subject RE: Best way to deal with NULL PDAcroForm fields
Date Tue, 08 Sep 2015 16:38:18 GMT
1.8.10

-----Original Message-----
From: Maruan Sahyoun [mailto:sahyoun@fileaffairs.de] 
Sent: Tuesday, September 08, 2015 11:20 AM
To: users@pdfbox.apache.org
Subject: Re: Best way to deal with NULL PDAcroForm fields

Hi Kevin,

> Am 08.09.2015 um 16:45 schrieb Kevin Ternes <KTernes@thegeneral.com>:
> 
> 
> I get a lot of weird documents.  When I try to set a particular field value, some of
them throw NullPointerExceptions from line PDAcroForm.getField(), line 291:
> 
> 287: COSArray fields =
> 288:    (COSArray) acroForm.getDictionaryObject(
> 289:        COSName.getPDFName("Fields"));
> 290:
> 291: for (int i = 0; i < fields.size() && retval == null; i++) 292:{
> 
> To avoid this, at first I was calling PDAcroForm.getFields() and checking that to see
if that was NULL but I realized that it would usually create a new fields array to return
which seemed wasteful.
> 
> Is the most efficient way to avoid this to first call:
>    COSArray fields =  (COSArray) acroForm.getDictionaryObject( 
> COSName.getPDFName("Fields")); myself and check if that is NULL?
> 
> 
> Secondary Question:
> The method PDAcroForm.getFields() does a not-NULL check of fields before calling fields.size().
> Is there a reason that this check is not performed in getField()?


which version of PDFBox are you using?

BR
Maruan

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


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


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


Mime
View raw message