gpt4 book ai didi

java - iTextPDF 签名 : how to not show signature fields, 但显示图像

转载 作者:行者123 更新时间:2023-12-01 22:53:55 25 4
gpt4 key购买 nike

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

最佳答案

PdfSignatureAppearance 有一个带有 RenderingMode 参数的 setter setRenderingModeRenderingMode 是具有以下值的枚举:

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);

关于java - iTextPDF 签名 : how to not show signature fields, 但显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58448091/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com