0

我使用 itextpdf-5 在 PDF 上签名。我想签署文件,但要使除图像之外的所有字段(原因、位置)都不可见。我可以在第三方程序中执行此操作(我附上了此类 PDF 的示例:签名存储了所有数据,但不显示)。我在我的程序中没有在文档中找到类似的东西(我附上了代码示例)

带有隐藏数据的示例 PDF

 private static void emptySignature(String src, String dest, String sigName, int page, int x, int y) {
    try {
        Image image = Image.getInstance(new File(currentPatient.getCurrentSign().getLocalFilePath()).toURL());;
        PdfReader reader = new PdfReader(src);
        FileOutputStream os = new FileOutputStream(dest);
        PdfStamper stamper = PdfStamper.createSignature(reader,os,'\0',new File("data/results/temp"),true);

        PdfSignatureAppearance appearance = stamper.getSignatureAppearance();
        appearance.setVisibleSignature(new Rectangle(x,y,x+80,y-60),page,sigName); 
        //Hide it!
        appearance.setReason("Nikita");
        appearance.setLocation("Sanitas");
        //No hide
        appearance.setImage(image);

        ExternalSignatureContainer external = new ExternalBlankSignatureContainer(PdfName.ADOBE_PPKLITE, PdfName.ADBE_PKCS7_DETACHED);
        MakeSignature.signExternalContainer(appearance,external,8192);
        os.close();
        reader.close();
        stamper.close();
    } catch (Exception ex) {}
}
4

1 回答 1

1

PdfSignatureAppearance有一个setRenderingModeRenderingMode参数的设置器。 RenderingMode是具有这些值的枚举:

public enum RenderingMode {
    /**
     * The rendering mode is just the description.
     */
    DESCRIPTION,
    /**
     * The rendering mode is the name of the signer and the description.
     */
    NAME_AND_DESCRIPTION,
    /**
     * The rendering mode is an image and the description.
     */
    GRAPHIC_AND_DESCRIPTION,
    /**
     * The rendering mode is just an image.
     */
    GRAPHIC
}

因此,要使除图像之外的所有字段(原因、位置)不可见,只需将渲染模式设置为GRAPHIC

appearance.setRenderingMode(RenderingMode.GRAPHIC);
于 2019-10-18T11:57:43.770 回答