Some test text!

Discord Logo

Chat with us

PDFTron is now Apryse, learn more here.

Nodejs / Guides / Add stamp annotation


PDFTron is now Apryse, learn more here.

Add a stamp annotation to a PDF in Node.js

A stamp in a PDF document is analogous to applying a rubber stamp on a paper document.

Apryse SDK benefits include:

  • Stamp PDF pages with text, images, or with other PDF pages.
  • Embed fonts and images, and copy graphical elements from one page to another.

Use Stamper to stamp content (text, image, PDF page)

To stamp text, image, and a PDF page to a PDF document.

async function main() {
  const doc = await PDFNet.PDFDoc.createFromURL(filename);
  const stamper = await PDFNet.Stamper.create(

  // Specifies if the stamp is to be stamped as an annotation.
  // note that stamps created with this setting do not work with SetAsBackground, HasStamps, and DeleteStamps, if annotation is true.

  await stamper.setAlignment(
  await stamper.setAlignment(
  const font = await PDFNet.Font.create(
  await stamper.setFont(font);
  const redColorPt = await PDFNet.ColorPt.init(1, 0, 0, 0);
  await stamper.setFontColor(redColorPt);
  await stamper.setTextAlignment(PDFNet.Stamper.TextAlignment.e_align_right);
  await stamper.setAsBackground(true);
  const pgSet = await PDFNet.PageSet.createRange(1, 2);
  await stamper.stampText(doc, "This is a title!", pgSet);

  const img = await PDFNet.Image.createFromURL(doc, imagename);
  await stamper.setAsBackground(false);
  const pgSetImage = await PDFNet.PageSet.createRange(1, 1);
  await stamper.stampImage(doc, img, pgSetImage);

  const srcDoc = await PDFNet.PDFDoc.createFromURL(src_filename);
  const srcPage = await srcDoc.getPage(1);
  await stamper.stampPage(doc, srcPage, pgSet);

Stamp a PDF File
Full code sample which shows how to stamp PDF pages with text, images, or with other PDF pages and how to add new content (or watermark).

About Stamper

Stamper can be used for PDF pages with text, images, or with other PDF content in only a few lines of code. Although Stamper is very simple to use compared to ElementBuilder/ElementWriter it is not as powerful or flexible. In case you need full control over PDF creation use ElementBuilder/ElementWriter to add new content to existing PDF pages as shown in the ElementBuilder sample project .

Get the answers you need: Support