Add Text Stamps to PDF in Java

Use text stamps when you need to add visible labels or watermarks to PDF pages.

Add a text stamp

Use this example when a page should display a rotated text stamp with custom styling.

  1. Open the source PDF Document.
  2. Create a TextStamp and configure its placement and text appearance.
  3. Add the stamp to the target page and save the document.
public static void addTextStamp(Path inputFile, Path outputFile) {
    try (Document document = new Document(inputFile.toString())) {
        TextStamp textStamp = new TextStamp("Sample Stamp");
        textStamp.setBackground(true);
        textStamp.setXIndent(100);
        textStamp.setYIndent(100);
        textStamp.setRotate(Rotation.on90);
        textStamp.getTextState().setFont(FontRepository.findFont("Arial"));
        textStamp.getTextState().setFontSize(14.0f);
        textStamp.getTextState().setFontStyle(FontStyles.Bold | FontStyles.Italic);
        textStamp.getTextState().setForegroundColor(Color.getDarkGreen());
        document.getPages().get_Item(1).addStamp(textStamp);
        document.save(outputFile.toString());
    }
}