Add signature to pdf with itext

2.8k views Asked by At

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

There are 1 answers

3
prashant On BEST ANSWER

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.