Aspose pdf java PdfileSignature设置权限不工作

Aspose pdf java PdfileSignature设置权限不工作,java,pdf,digital-signature,aspose,Java,Pdf,Digital Signature,Aspose,我正在尝试使用Aspose pdf java对文档进行数字签名。这是我的密码 public ByteArrayOutputStream signDocument(Document doc, String signedBy) throws Exception { PdfFileSignature pdfSignSingle = new PdfFileSignature(); pdfSignSingle.bindPdf(doc); pdfSignSi

我正在尝试使用Aspose pdf java对文档进行数字签名。这是我的密码

public ByteArrayOutputStream signDocument(Document doc, String signedBy) throws Exception {

        PdfFileSignature pdfSignSingle = new PdfFileSignature();
        pdfSignSingle.bindPdf(doc);
        pdfSignSingle.setCertificate(prop.getSigningKeyStorePath(), prop.getKeystorePassword());
        PKCS7 signature = new PKCS7(prop.getSigningKeyStorePath(), prop.getKeystorePassword());
        pdfSignSingle.setSignatureAppearance(prop.getSimploudLogo());

        signature.setAuthority("Authority");
        signature.setDate(new Date());
        signature.setContactInfo("email");
        signature.setLocation("Location");
        signature.setReason("reason");
        pdfSignSingle.sign(1, true, new java.awt.Rectangle(100, 100, 200, 200), signature);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        pdfSignSingle.save(baos);
        pdfSignSingle.dispose();
        doc.dispose();
        return baos;
    }
中显示了签名在adobeReader中的外观

正如您所见,图像和权限均未显示。我尝试将图像同时以pdf和png格式显示。我也试着使它比矩形区域小。至于权威,我真的需要它是可定制的,以便在图片的第一行文字可以被编辑
由“customParameter”签名

该API提供了另一个类,即
SignatureCustomAppearance
,可进一步用于设置签名的属性,如签名日期、原因、位置等。请检查以下可满足您要求的完整代码段:

String inputFile = "doc.pdf";
String outSignedFile = "out_20.9.pdf";
// Create PdfFileSignature instance
com.aspose.pdf.facades.PdfFileSignature pdfSignSingle = new com.aspose.pdf.facades.PdfFileSignature();
// Bind the source PDF by reading contents of Stream
pdfSignSingle.bindPdf(inputFile);

PKCS7 pkcs = new PKCS7("mykey2.pfx", "pass");
pkcs.setAuthority("Authority");
pkcs.setDate(new Date());
pkcs.setContactInfo("email");
pkcs.setLocation("Location");
pkcs.setReason("reason");
pkcs.setImage(new FileInputStream("simpleLogo.png"));

SignatureCustomAppearance sca = new SignatureCustomAppearance();
sca.setDateSignedAtLabel(null);
sca.setDigitalSignedLabel(null);
sca.setShowReason(true);
sca.setShowLocation(true);
sca.setShowContactInfo(true);

pkcs.setCustomAppearance(sca);

pdfSignSingle.sign(1, true, new java.awt.Rectangle(100, 100, 200, 200), pkcs);
// Set image for signature appearance
//pdfSignSingle.setSignatureAppearance("simpleLogo.png");
// Save final output
pdfSignSingle.save(outSignedFile);

正如问题下方的评论所述,同样的查询也发布在Aspose.PDF官方论坛以及“”上,并且在那里也提供了解决方案。

我们相信我们已经在Aspose.PDF官方支持论坛()中回复了您的类似查询。我们要求您跟进,以便我们能够相应地帮助您。这是Asad Ali,我在Aspose担任开发人员福音传道者。