Add signature to pdf with itext

拜拜、爱过 提交于 2019-12-14 03:37:42

问题


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.

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


回答1:


Use itext pdfstamper to write the signature.

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

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

Set the text and dimensions and then.

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

Then close the reader, stamper and outputstream.

The signature would be displayed.



来源:https://stackoverflow.com/questions/41382241/add-signature-to-pdf-with-itext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!