我在使用PDFBox 2.0.0-RC3時遇到麻煩,並且在PDF中生成數字簽名字段。PDFBox簽名字段沒有得到很好的認可
這是一段代碼我使用:
public static void main(String[] args) throws IOException, URISyntaxException
{
PDDocument document;
document = new PDDocument();
PDPage page = new PDPage(PDRectangle.A4);
document.addPage(page);
PDAcroForm acroForm = new PDAcroForm(document);
document.getDocumentCatalog().setAcroForm(acroForm);
PDSignatureField signatureBox = new PDSignatureField(acroForm);
signatureBox.setPartialName("ENSGN-MY_SIGNATURE_FIELD-001");
acroForm.getFields().add(signatureBox);
PDAnnotationWidget widget = signatureBox.getWidgets().get(0);
PDRectangle rect = new PDRectangle();
rect.setLowerLeftX(50);
rect.setLowerLeftY(750);
rect.setUpperRightX(250);
rect.setUpperRightY(800);
widget.setRectangle(rect);
page.getAnnotations().add(widget);
try {
document.save("/tmp/mySignatureFieldGEN_PDFBOX.pdf");
document.close();
} catch (Exception io) {
System.out.println(io);
}
}
的代碼生成一個PDF文檔,我與Acrobat Reader中打開它,這就是結果:
正如你可以看到,左邊的簽名面板是無效的,但是左邊的簽名字段存在並且工作。
我生成PDFTron相同的PDF。這是結果:
在這種情況下在左側顯示正確的簽名字段的存在的簽名板。
我想獲得這第二種情況下(正確的),但我不明白爲什麼PDF盒可以做到這一點。
非常感謝
@Tilman運還沒有想簽下 – mkl
@mkl哎呀,是的,我完全誤解了。 –