当我使用标准版本为的Apache PDFBox 为"fieldType": "Sig"
给出一些随机名称,例如{<1>}的“ 测试”时,会出现此异常> 2.0.13 ,因为它是它的最新版本,但是当我给全限定名加上“ 签名”时,它可以正常工作。请让我知道可能是此问题的根本原因。
org.apache.pdfbox.cos.COSString无法转换为org.apache.pdfbox.cos.COSDictionary
堆栈跟踪:
java.lang.ClassCastException: org.apache.pdfbox.cos.COSString cannot be cast to org.apache.pdfbox.cos.COSDictionary
at org.apache.pdfbox.pdmodel.interactive.form.PDSignatureField.getValue(PDSignatureField.java:170)
at org.apache.pdfbox.pdmodel.interactive.form.PDSignatureField.getSignature(PDSignatureField.java:116)
at org.apache.pdfbox.pdmodel.PDDocument.findSignatureField(PDDocument.java:460)
at org.apache.pdfbox.pdmodel.PDDocument.addSignature(PDDocument.java:365)
代码:
private PDSignature findExistingSignature(PDAcroForm pdAcroForm, String signatureFieldName) {
PDSignature signature = null;
if (pdAcroForm != null) {
PDSignatureField signatureField = (PDSignatureField) pdAcroForm.getField(signatureFieldName);
System.out.println("signatureField >>>>>>>>>>>>>>>>>>."+ signatureField); // !!!!!!!!!
if (null != signatureField) {
signature = signatureField.getSignature(); // !!!!!!!!!
if (signature == null) {
signature = new PDSignature();
signatureField.getCOSObject().setItem(COSName.V, signature);
} else {
throw new IllegalStateException("The signature field received ::" + signatureFieldName + " is already signed.");
}
}
}
return signature;
}
这是印刷的
signatureField >>>>>>>>>>>>>>>>>>>>。Vimal {类型:PDSignatureField值:COSString {}}
请在任何pdf文件中使用空白的签名字段,以便 签名字段的/ V元素中没有签名字典,但是作为iam的测试字符串无法附加示例PDF。