推荐答案问题更新后剩下的问题是替换现有的 AcroForm 定义:The remaining problem after your question update is that you replace the existing AcroForm definition:// Add a new AcroForm and add that to the documentPDAcroForm acroForm = new PDAcroForm(document);document.getDocumentCatalog().setAcroForm(acroForm);这种变化太大,超出了允许范围,超出了您实际想要的范围.That changes too much, more than allowed and more than you actually want.您想要的是检索现有的 AcroForm 定义,并仅将其及其字段条目标记为保存:What you want is to retrieve the existing AcroForm definition and only mark it and its Fields entry for saving:PDAcroForm acroForm = document.getDocumentCatalog().getAcroForm();acroForm.getCOSObject().setNeedToBeUpdated(true);COSObject fields = acroForm.getCOSObject().getCOSObject(COSName.FIELDS);if (fields != null) fields.setNeedToBeUpdated(true);有了这些代码,我得到了您的示例文档:With that code I get for your example document: (当然,对于现有 AcroForm 定义的 文档,您可能要添加一个新的定义,所以(Of course, for documents without an existing AcroForm definition you will probably want to add a new one, soPDAcroForm acroForm = document.getDocumentCatalog().getAcroForm();if (acroForm == null) { acroForm = new PDAcroForm(document); document.getDocumentCatalog().setAcroForm(acroForm);}acroForm.getCOSObject().setNeedToBeUpdated(true);COSObject fields = acroForm.getCOSObject().getCOSObject(COSName.FIELDS);if (fields != null) fields.setNeedToBeUpdated(true);可能是完整的变体.) 这篇关于PDFBox 2.0创建签名字段并使用已签名的文档保存增量文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-22 21:28