首页 文章

使用Pdfbox API写入后,PDF acroform字段在Adobe Reader中变得不可编辑

提问于
浏览
1

我正在阅读具有可编辑字段的PDF,并且可以通过Adobe Reader打开字段来编辑字段 . 我正在使用PDFBox API生成输出PDF,其中包含输入PDF中可编辑字段的数据 . 输出PDF可以使用Adobe Reader打开,我可以看到字段值,但我无法直接从Adobe阅读器编辑这些字段 .

此问题还有一张JIRA票据,根据此链接无法解决:

https://issues.apache.org/jira/browse/PDFBOX-1121

任何人都可以告诉我这是否得到解决?另外,如果可能,请回答与我的问题相关的以下问题:

  • 为了编辑Adobe Reader的输出PDF,是否需要明确设置保护策略或访问权限?

  • 每次打开使用pdfbox API编写的PDF时,都会收到以下消息提示:

“文档自创建以来已更改,并且不再使用扩展功能......”

我使用的是PdfBox 1.8.6 jar和Adobe Reader 11.0.8 . 如果有人能帮我解决这个问题,我将非常感激 .

添加了代码段以帮助响应者进行调试:

String outputFileNameWithPath = "C:\myfolder\testop.pdf";
PDDocument pdf = null;
pdf = PDDocument.load( outputFileNameWithPath );

PDDocumentCatal og docCatalog = pdf.getDocumentCatalog();
PDAcroForm acroForm = docCatalog.getAcroForm();
//The map pdfValues is a collection of the data that I need to set in the PDF
//I am unable to go into the details of my data soutce
// The key in the data map corresponds to the PDField's expanded name and data
//  corresponds to the data that I am trying to set.
Iterator<Entry<String, String>> iter=pdfValues.entrySet().iterator();
String name=null;
String value=null;
PDField field=null;
//Iterate over all data and see if the PDF has a matching field.
while(iter.hasNext()) {
    Map.Entry<String, String> currentEntry=iter.next();
    name=currentEntry.getKey();
    value=currentEntry.getValue();
    if(name!=null) {
        name=CommonUtils.fromSchemaNameToPdfName(name);
        field=acroForm.getField(name);      
    }
    if( field != null && value!=null )
        {           
            field.setValue( value ); //setting  the values once field is found.
        }
}
// Set access permissions / encryption here before saving
pdf.save(outputFileNameWithPath);

谢谢 .

1 回答

  • 0

    文档自创建以来已更改,并且不再使用扩展功能....

    这表示原始表单已启用Reader,即使用Adobe持有的私钥将已集成的使用权数字签名应用于文档,该私钥告诉Adobe Reader它将为查看的用户提供一些额外的功能那种形式 .

    如果您不希望在使用PDFBox填写表单期间破坏该签名,则需要确保自己

    • 不做任何更改,但形成填写和

    • 将更改保存为增量更新 .

    如果您提供了表单填写代码和源PDF,则可以更详细地分析 .

相关问题