[]
        
(Showing Draft Content)

Watermark Annotation

A watermark annotation defines graphics that appear on a page at a fixed size and position, regardless of the dimensions of the printed page. Watermarks are commonly used to display labels such as drafts, confidential marks, or other document status indicators.

Watermark-Annotation.png

Use the WatermarkAnnotation class to add watermark annotations to a PDF document.

const inputDocData = await Util.loadFile("CompleteJavaScriptBook.pdf");
const doc = PdfDocument.load(inputDocData);

//Loop over pages, add a watermark to each page:
for (const page of doc.pages)
{
    // Create an instance of WatermarkAnnotation class and set its relevant properties
    const watermark = new WatermarkAnnotation();
    watermark.rect = { x: 72, y: 72, width: page.width - 72 * 2, height: page.height - 72 * 2 };
    watermark.text = "DRAFT";
    watermark.textFormat = new Format({
        font: Font.getPdfFont(StandardPdfFont.CourierBold),
        fontSize: 108,
        foreColor: "#FF000080" // semitransparent RED color
    });
    watermark.page = page;
}
const docData = doc.savePdf();
Util.saveFile("WatermarkAnnotation.pdf", docData);