pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Zhang, Ge" <g1zh...@ucsd.edu>
Subject AcroForm data is saved but not viewable
Date Thu, 17 Apr 2014 20:24:03 GMT
Hi guys:

   I tried to fill a existing PDF form using  PDFBox, the fields I tried to fill is textfield
and check box. It runs OK, and I can verify all values are correctly set in acroFom, but I
get some strange results while trying to view it:

    1,  after save the doc, and open it using Adobe Reader, the text data is missing, but
the check box is in the right place. If searching the pdf using text editor, all values are
there, which means there are inserted, but not picked up by AdobeReader.

    2, If I print the pdf or open it through a web browser, all field values shows.

    I am new to this project and PDF. I will appreciate if anybody can help me to find out
the reason why the field values are not viewable in Adobe Reader.

    The code I use to fill the form is below the email.

Thank you!


public static void main(String[] args) {
PDDocument doc = null;
try {
doc = PDDocument.load("./test.pdf");
PDAcroForm acroForm = doc.getDocumentCatalog().getAcroForm();

PDField field = (PDField) acroForm.getFields().get(0);
setField(acroForm, "testform[0].Page1[0].last_name[0]", "HELLO");
setField(acroForm, "testform[0].Page1[0].first_name[0]", "World");
setFieldChecked(acroForm, PDF_700U_Constants.FILER_INFO_YES);

} catch (Exception e) {
} finally {
if (doc != null) {
try {
} catch (Exception e2) {
System.err.println("Unable to close document");

        protected static void setField(PDAcroForm acroForm, String name, String value) throws
IOException {
PDField field = acroForm.getField(name);
if (field != null) {
} else {
System.err.println("*********************No field found with name:" + name);
protected static void setFieldChecked(PDAcroForm acroForm, String name) throws IOException
PDField field = acroForm.getField(name);
if (field != null) {
((PDCheckbox) field).check();
} else {
System.err.println("No name found for this field: " + name);

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message