Hi. I was able to solve this using the code below:
List fieldsToSet = new ArrayList();
PDDocument pdfDoc = PDDocument.load("somepath");
Iterator fields =
pdfDoc.getDocumentCatalog().getAcroForm().getFields().iterator();
while(fields.hasNext){
PDField field = fields.next();
String someValue = aFunction(field.getAlternateFieldName());
field.setValue(someValue);
fieldsToSet.add(field);
}
pdfDocument.getDocumentCatalog().getAcroForm().setFields(fieldsToSet);
pdfDocument.save("someotherpath");
Regards,
Ravi.
From: Ravi Chilakapati
Sent: Monday, September 27, 2010 4:33 PM
To: '[email protected]'
Subject: Reg. pdf editing and saving
Hello!
I have recently started using PDFBox and am stuck with one issue.
We have a template that needs to be populated partially.
We are doing something very close the code below:
PDDocument pdfDoc = PDDocument.load("somepath");
Iterator fields =
pdfDoc.getDocumentCatalog().getAcroForm().getFields().iterator();
while(fields.hasNext){
PDField field = fields.next();
String someValue = aFunction(field.getAlternateFieldName());
field.setValue(someValue);
}
pdfDocument.save("someotherpath");
The code is being compiled and I am able to run it. But when I open the output
pdf file with Adobe Reader 9.3, I am unable to see the populated values.
However, the size of the output field is greater than the size of the input pdf
file.
I have also written a separate utility where I am opening the output file and
printing the values of all the fields. And I am able to see the values that I
set. They are showing up!
How can I resolve this strange error? Any help will be greatly appreciated!
Thanks and Regards,
Ravi.