Digital visible Sign with pdfbox 1.8.8

huangapple go评论77阅读模式
英文:

Digital visible Sign with pdfbox 1.8.8

问题

我正在使用 pdfbox 1.8.8 生成 PDF 上的可见签名。
以下是我的代码。我无法在 PDF 中获得可见签名。
我得到的只是一个没有内容的矩形框。

PDDocument document = PDDocument.load(temp);
document.getCurrentAccessPermission().setCanModify(false);
PDSignature signature = new PDSignature();
signature.setFilter(PDSignature.FILTER_ADOBE_PPKLITE);
signature.setSubFilter(PDSignature.SUBFILTER_ADBE_PKCS7_DETACHED);
signature.setName("XyZ");
signature.setLocation("XYZ");
signature.setReason("test");
signature.setSignDate(Calendar.getInstance());

InputStream image = new FileInputStream("download.png");

PDVisibleSignDesigner signatureDesigner = new PDVisibleSignDesigner(
        document, image, document.getNumberOfPages());
signatureDesigner.xAxis(0).yAxis(0).zoom(-80).signatureFieldName("signature");

PDVisibleSigProperties signatureProperties = new PDVisibleSigProperties();
signatureProperties.signerName("Xyz").signerLocation("Xyz")
        .signatureReason("Test").preferredSize(100).page(1)
        .visualSignEnabled(true).setPdVisibleSignature(signatureDesigner).buildSignature();

SignatureOptions options = new SignatureOptions();
options.setVisualSignature(signatureProperties);

document.addSignature(signature, (SignatureInterface) this, options);

/* Sign */
document.saveIncremental(tempIn, tempOut);

实际结果:

Digital visible Sign with pdfbox 1.8.8

预期结果:我希望得到包含图像和签名字段内容的这个区块。

英文:

I'm using pdfbox 1.8.8 to generate Visible sign on PDF.
Here is my code. I'm not able to get visible Sign in pdf.
All I get is a rectangle box having no content.

PDDocument document = PDDocument.load(temp);
        document.getCurrentAccessPermission().setCanModify(false);
        PDSignature signature = new PDSignature();
        signature.setFilter(PDSignature.FILTER_ADOBE_PPKLITE);
        signature.setSubFilter(PDSignature.SUBFILTER_ADBE_PKCS7_DETACHED);
        signature.setName("XyZ");
        signature.setLocation("XYZ");
        signature.setReason("test");
        signature.setSignDate(Calendar.getInstance());
        
        InputStream image = new FileInputStream("download.png");
        
        PDVisibleSignDesigner signatureDesigner = new PDVisibleSignDesigner(
                document, image, document.getNumberOfPages());
        signatureDesigner.xAxis(0).yAxis(0).zoom(-80).signatureFieldName("signature");

        PDVisibleSigProperties signatureProperties = new PDVisibleSigProperties();
        signatureProperties.signerName("Xyz").signerLocation("Xyz")
                .signatureReason("Test").preferredSize(100).page(1)                    
       .visualSignEnabled(true).setPdVisibleSignature(signatureDesigner).buildSignature();

        SignatureOptions options = new SignatureOptions();
        options.setVisualSignature(signatureProperties);

        document.addSignature(signature, (SignatureInterface) this, options);

        /* Sign */
        document.saveIncremental(tempIn, tempOut);

Actual Result :

Digital visible Sign with pdfbox 1.8.8

Expected Result : I want this block with the Image and signature field content.

答案1

得分: 1

1.8.*版本的示例仅支持JPEG文件。

我建议使用2.0.*版本的PDFBox,其中包含两个数字签名示例(包括一个带文本的示例),它们更加灵活,提供了更多功能。

英文:

The example in 1.8.* supports only JPEG files.

I recommend to use the 2.0.* PDFBox version, there are two examples of digital signing (including one with text), and they are more flexible and offer more features.

huangapple
  • 本文由 发表于 2020年9月21日 17:15:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/63989348.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定