pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Richard Johnson <rich...@ytivarg.com>
Subject External Tool?
Date Fri, 27 Mar 2015 03:38:01 GMT
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)


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

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?

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

--------

-- 
Richard Johnson



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


Mime
View raw message