我使用itextpdf-5在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) {}
}
PdfSignatureAppearance
具有带有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);