You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Peter Adelmann <pa...@collaborative.com> on 2008/10/13 18:10:58 UTC

Trying to update text in pdf and saving to new name, but.....

Hello,

 

First off, this is a great tool.  I'm new to it.  The concept of
dynamically change pdf's on the fly is a huge development...Thanks.

 

I'm having a bit of an issue trying to change a field value in a
PDAcroForm object which I'm opening up.  I'm trying to modify values on
the Form on the fly and then save the form to a new name.  I'm able to
open the original Form, find the field, update it, and save to a new
name using the PDDocument.save(path + name).  However when I open up the
new pdf, the updated text shows up twice, overlapping itself.  I've
enclosed a picture of what's happening to illustrate.

 

I've attached how the form is coming out.  Spm Assassin is giving me a
hard time concerning the binary.  I've attached it, hopefully my score
will be lower....

 

Here's a code snippet:

 

PDDocument pdfDocument =    PDDocument.load("template.pdf");     

PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();

PDAcroForm acroForm = docCatalog.getAcroForm();

PDField field = acroForm.getField("BROKERNAME");   //I've iterated
through the form, this field exists

field.setValue("William Schmidt");  //overwrite existing value

pdfDocument.save("newDoc.pdf");

//this is greatly simplified there are a couple of try/catch blocks in
here as well

 

 

Any idea why this is?  I'm guessing I'm to blame for this; and yes I do
need to read more concerning the Adobe Document structure, but I'm
trying to do a Proof of Concept and this is almost correct....which
unfortunately is still !correct....

Thanks,

Peter