pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Maruan Sahyoun <sahy...@fileaffairs.de>
Subject Re: External Tool?
Date Fri, 27 Mar 2015 07:24:18 GMT
Hi,

> Am 27.03.2015 um 04:38 schrieb Richard Johnson <richard@ytivarg.com>:
> 
> Hi,
> 
> I'm using pdfbox to fill fields in pdf forms.  The problem is that most forms we 
> need to fill arrive "broken."  Broken in the sense of we can load the file, we 
> can find the field by name, but the first field on the page invariably gives us 
> the nfamous exception:  
> 
> java.lang.NullPointerException
> 	at 
> org.apache.pdfbox.pdmodel.interactive.form.PDAppearance.calculateFontSize(PDAppearance.java:923)
> 
> 

could you give PDFBox 2.0 a try?

> This is the sign that the form is "broken."  Previously we used 
> MasterPDFEditor to save the document, build the fields on it (all over again) 
> and everything worked.  Now, apparently that tool creates equally broken 
> documents that we cannot fill with pdfbox.
> 
> 1.  Is there a better tool to use, one that would actually save usable files 
> and not cost an arm and a leg?  (For instance should I use pdfbox to do this 
> work programmatically?)

the issue is probably because of a missing/wrong Resources entry for the form and/or the field.
That can be resolved using PDFBox too.


> 
> 2. Regardless of the answer to question 1, could I be doing something better 
> in terms of opening and manipulating the file?  (code sample below.)
> 
> 3.  Anything else that probably well known but I don't know enough to ask?

Would you have a sample file to inspect? Please upload that to a public location as the mailing
list doesn't support attachments.



> 
> ----- sample:
> 
> PDDocument pdfDocument;
> PDAcroForm form;
> try {
>        pdfDocument = PDDocument.load(templateLocation);
>        form = pdfDocument.getDocumentCatalog().getAcroForm();
> } catch (IOException ioe) {
>                log.log(Level.SEVERE, "Unable to load a template: {0}\n{1}", 
>                         new Object[]{templateLocation, ioe});
> }
> 
> PDField employerName = form.getField("Name_of_Employer");
> employerName.setValue("TEST");           <<<------ NPE here -<<<<<<<<<

a) try using PDFBox 2.0 as this has some enhancements regarding acroforms and is the base
for further enhancements in this area.
b) you'd need to check if the field exists. employerName could already be null. The same for
form earlier before.

BR
Maruan

> 
> --------
> 
> -- 
> Richard Johnson
> 
> 
> 
> ---------------------------------------------------------------------
> 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