For the complete documentation index, see llms.txt. This page is also available as Markdown.

Adding a stamp to PDFs using Javascript

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.

Stamp content (text, image) with canvas

The setWatermark method enables you to draw custom content on a page as a bitmap.

To preserve vector data use the stamper tool.

const { documentViewer } = instance.Core;
const path = '/samples/full-apis/TestFiles/butterfly.png'

// Promise resolves with options object
const promise = new Promise(resolve => {
  const img = new Image();
  const options = {
    custom: async (ctx, pageIndex, pageWidth, pageHeight) => {

      ctx.font = '50px serif';
      ctx.fillText('Hello world', 50, 90);

      ctx.drawImage(
        img,
        pageWidth / 2 - img.width / 2,
        pageHeight / 2 - img.height / 2
      );

      // the pageIndex is also passed in so you could have
      // a different watermark for each page
    }
  };
  img.onload = () => { 
    return resolve(options);
  };
  img.src = path;
});

documentViewer.setWatermark(promise);

Stamp content (text, image, PDF page) with Stamper tool

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

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.

Last updated

Was this helpful?