[Solved] Add signature to pdf with itext


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.

3

solved Add signature to pdf with itext