Some test text!

Loading...
Guides
Add stamp annotation

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.

PDFTron 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(
    PDFNet.Stamper.SizeType.e_relative_scale,
    0.5,
    0.5
  );

  // 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.
  //stamper.setAsAnnotation(true);

  await stamper.setAlignment(
    PDFNet.Stamper.HorizontalAlignment.e_horizontal_right,
    PDFNet.Stamper.VerticalAlignment.e_vertical_bottom
  );
  await stamper.setAlignment(
    PDFNet.Stamper.HorizontalAlignment.e_horizontal_center,
    PDFNet.Stamper.VerticalAlignment.e_vertical_top
  );
  const font = await PDFNet.Font.create(
    doc,
    PDFNet.Font.StandardType1Font.e_courier
  );
  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);
}
PDFNet.runWithCleanup(main);

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

PDFTron live tech update & run-through: Jan 20th at 11 am PT