使用itext将签名添加到pdf [英] Add signature to pdf with itext

查看:1402
本文介绍了使用itext将签名添加到pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用itext以直接添加签名而不是转换为图像的方式将电子签名(人在平板电脑上签名)添加到PDF,因此,eIDAS法规,基本电子签名程序得到维护。

How do I add a e-signature(persons makes his signature on a tablet) to a PDF using itext in a way a signature is directly added not converted to an image so, eIDAS regulations, basic electronic signature procedure is uphold.

我不希望带有证书的数字签名只能写在平板电脑上的人签名。

I do not want a digital signature with a certificate only a person signature written on a tablet.

一个例子是signosigns app: http://en.signotec.com/portal/seiten/download-signosign-mobile-for-android-900000340-10002.html

An example would be signosigns app: http://en.signotec.com/portal/seiten/download-signosign-mobile-for-android-900000340-10002.html

推荐答案

使用itext pdfstamper写签名。

Use itext pdfstamper to write the signature.

FileOutputStream os = new FileOutputStream(destFileName);
PdfStamper stamper = new PdfStamper(reader, os);

读者是sec文件阅读器,然后获得压模。

Where reader is the sec file reader then once you have got the stamper.

PdfPatternPainter painter = stamper.getOverContent(1).createPattern(200, 150);
painter.setColorFill(BaseColor.ORANGE);
painter.beginText();
painter.setTextMatrix(AffineTransform.getTranslateInstance(0, 50));
painter.setFontAndSize(BaseFont.createFont(), 70);
painter.showText(waterMarkString);
painter.endText();

for (int i = reader.getNumberOfPages(); i > 0; i--) {
    PdfContentByte overContent = stamper.getOverContent(i);
    overContent.setColorFill(new PatternColor(painter));
    overContent.rectangle(200, 300, 200, 150);
    overContent.fill();
}

设置文字和尺寸然后。

reader.close();
stamper.close();
os.close();

然后关闭阅读器,压模和输出流。

Then close the reader, stamper and outputstream.

将显示签名。

这篇关于使用itext将签名添加到pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆