【问题标题】:iTextPDF Signature: how to not show signature fields, but show an imageiTextPDF 签名:如何不显示签名字段,但显示图像
【发布时间】:2019-10-18 09:38:56
【问题描述】:

我使用 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,'\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) {}
}

【问题讨论】:

    标签: java itext sign pdfstamper


    【解决方案1】:

    PdfSignatureAppearance 有一个带有 RenderingMode 参数的设置器 setRenderingMode。 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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-12
      • 2012-11-17
      • 1970-01-01
      • 1970-01-01
      • 2017-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多