In PDFBox 2.x I put /Lock dictionary to signature field:import org.apache.pdfbox.cos.COSDictionary;import org.apache.pdfbox.cos.COSName;import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;import org.apache.pdfbox.pdmodel.interactive.form.PDSignatureField;public class SigningUtils { public static final COSName COS_NAME_LOCK = COSName.getPDFName("Lock"); public static final COSName COS_NAME_ACTION = COSName.getPDFName("Action"); public static final COSName COS_NAME_ALL = COSName.getPDFName("All"); public static final COSName COS_NAME_SIG_FIELD_LOCK = COSName.getPDFName("SigFieldLock"); public static void setLock(PDSignatureField pdSignatureField, PDAcroForm acroForm) { COSDictionary lockDict = new COSDictionary(); lockDict.setItem(COS_NAME_ACTION, COS_NAME_ALL); lockDict.setItem(COSName.TYPE, COS_NAME_SIG_FIELD_LOCK); pdSignatureField.getCOSObject().setItem(COS_NAME_LOCK, lockDict); }}Then I sign the signature field:PDSignature signature = findExistingSignature(document, signatureFieldName); //This is some method to find signature field and create PDSignature dictionarysignature.setFilter(PDSignature.FILTER_ADOBE_PPKLITE);signature.setSubFilter(PDSignature.SUBFILTER_ADBE_PKCS7_DETACHED);signature.setName("blablabla");signature.setLocation("blablabla");signature.setReason("blablabla");signature.setSignDate(Calendar.getInstance());document.addSignature(signature, this);Everything looks allright except that when I open signed document in Adobe Acrobat it complains the content of the document was changed. If I don't add the /Lock dictionary the everything is fine.Anyone has any idea what is wrong? 解决方案 The problem is that PDFBox signing does not take the Lock dictionary into account.According to ISO 32000-1 (and also similarly ISO 32000-2):Thus, the expected handling of a signature Lock dictionary includes the addition of matching FieldMDP transform data to the signature field value. PDFBox signing does not do so by default.You can manually do it like this during signing:PDSignatureField signatureField = FIND_YOUR_SIGNATURE_FIELD_TO_SIGN;PDSignature signature = new PDSignature();signatureField.setValue(signature);COSBase lock = signatureField.getCOSObject().getDictionaryObject(COSName.getPDFName("Lock"));if (lock instanceof COSDictionary){ COSDictionary lockDict = (COSDictionary) lock; COSDictionary transformParams = new COSDictionary(lockDict); transformParams.setItem(COSName.TYPE, COSName.getPDFName("TransformParams")); transformParams.setItem(COSName.V, COSName.getPDFName("1.2")); transformParams.setDirect(true); COSDictionary sigRef = new COSDictionary(); sigRef.setItem(COSName.TYPE, COSName.getPDFName("SigRef")); sigRef.setItem(COSName.getPDFName("TransformParams"), transformParams); sigRef.setItem(COSName.getPDFName("TransformMethod"), COSName.getPDFName("FieldMDP")); sigRef.setItem(COSName.getPDFName("Data"), document.getDocumentCatalog()); sigRef.setDirect(true); COSArray referenceArray = new COSArray(); referenceArray.add(sigRef); signature.getCOSObject().setItem(COSName.getPDFName("Reference"), referenceArray);}signature.setFilter(PDSignature.FILTER_ADOBE_PPKLITE);signature.setSubFilter(PDSignature.SUBFILTER_ADBE_PKCS7_DETACHED);signature.setName("blablabla");signature.setLocation("blablabla");signature.setReason("blablabla");signature.setSignDate(Calendar.getInstance());document.addSignature(signature [, ...]);(CreateSignature helper method signExistingFieldWithLock)Concerning the P entry in the signature Lock dictionary discussed in the comments: This entry has been introduced in the Adobe supplement to ISO 32000, extension level 3. 这篇关于“锁定"签名字段中的词典是签名后签名损坏的原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-22 21:33