Java – form field values set using pdfbox are not visible in adobe reader

I tried to use some Apache PDF@R_493_2419 @(1.8.5) to set some problems I have several different static PDFs that I use for testing Using the following code, I can set the value of the form field and save the generated PDF I can then open this PDF in adobe reader and view the results:

PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
pdfTemplate.setAllSecurityToBeRemoved(true);
PDAcroForm acroForm = docCatalog.getAcroForm();
List fields = acroForm.getFields();     
Iterator fieldsIter = fields.iterator();        
while( fieldsIter.hasNext())
{
    PDField field = (PDField)fieldsIter.next();         
    if(field instanceof PDText@R_493_2419@){
        ((PDText@R_493_2419@)field).setValue("STATIC PDF@R_493_2419@ EDIT");
    }
}

Then I finally saved the form For static PDF:

>Pdf version: 1.6 (acrobat 7. X) > PDF version: 1.7 (acrobat 8. X)

It's a good job I can open the document in adobe reader Xi and view the correct value in the form

For static PDF:

>Pdf version: 1.7 Adobe extension level 3 (acrobat 9. X) > PDF version: 1.7 Adobe extension level 8 (acrobat x) > PDF version: 1.7 Adobe extension level 11 (acrobat XI)

This doesn't seem to work. When I open the result form in adobe reader Xi, these fields don't seem to be filled in However, if I open PDF in the PDF viewer of Firefox or Chrome browser, these fields will be filled in

How do I set these fields so that values are displayed when viewed in adobe reader Xi?

Edit: sample PDF can be found here: https://github.com/bamundson/PDFExample

Solution

The main difference between your PDFs is the table technology used:

> Test_ 9. PDF use the good ol'fashioned acroform form form; > Test_ 10.pdf and test_ 10.pdf on the other hand, a mixed form with acroform representation and xfa (Adobe XML forms Architecture) representation is used

Xfa aware PDF viewers (i.e. the most important adobe reader and Adobe Acrobat) use the xfa information in the file when xfa unaware viewers (i.e. most others) use the acroform information

PDF@R_493_2419 @The main reason is that xfa doesn't know This means, in particular, pdacroform The pdfield object returned by getfields () only represents acroform information Therefore, your(( PDText@R_493_2419 @) field) setValue(“STATIC PDF@R_493_2419 @The edit() call affects only the acroform representation of the form

This explains your observation

(as far as I know, xfa doesn't know that Firefox and chrome integrate PDF viewers.)

So,

There are basically two ways:

>To remove an xfa entry from the acroform Dictionary:

acroForm.setXFA(null);

Without xfa, adobe reader will also use acroform form form information. > Edit acroform and xfa information You can use xfa information retrieval

PDXFAResource xr = acroForm.getXFA();

And use the underlying XML to extract

xr.getDocument()

Then, you can edit the XML, put the generated XML into a stream that can be wrapped in pdxfaresource, and then you can use acroform Setxfa (...) to set

Option 1 is certainly easier to implement, and it only applies to mixed documents If you also have to edit a pure xfa form, you need to implement option 2

IText has some explicit support for xfa forms

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>