iTextPDF 签名:如何不显示签名字段,但显示图像

iTextPDF Signature: how to not show signature fields, but show an image

我使用 itextpdf-5 在 PDF 上签名。我想在文档上签名,但要隐藏除图像以外的所有字段(原因、位置)。我可以在第三方程序中做到这一点(我附上了这样一个 PDF 的示例:签名存储所有数据,但不显示)。 我在我的程序中没有在文档中找到类似的东西(我附上代码示例)

Example PDF with hide data

 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,'[=10=]',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) {}
}

PdfSignatureAppearance 有一个 setter setRenderingMode 和一个 RenderingMode 参数。 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);