> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/web/edit-page-content/stamp.md).

# Adding a stamp to PDFs using Javascript

Learn how to create stamp annotations in PDF documents with our comprehensive guide. Stamp text, images, or other PDF pages easily with Apryse SDK. Stamp content efficiently with Stamper tool. The Apr

{% hint style="warning" %}
Try our [creating stamp annotations](/web/annotation/annotation-types/stampannotation.md) guide if you're looking specifically for stamping annotations.
{% endhint %}

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, PDF page) with Stamper tool

{% hint style="warning" %}
Make sure you have [Full API enabled in WebViewer.](/web/what-is-webviewer/full-api.md)
{% endhint %}

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

{% tabs %}
{% tab title="JavaScript (SDK v8.0+)" %}
{% code lineNumbers="true" %}

```js
let imageName = 'path to your image file';
let fileName = 'path to your PDF file';

WebViewer({
  fullAPI: true,
  // other constructor options
}, viewerElement).then(instance => {
  const { documentViewer, PDFNet } = instance.Core;

  document.getElementById('myBtn').addEventListener('click', async () => {
    await PDFNet.initialize();
    const doc = await documentViewer.getDocument().getPDFDoc();

    // Run PDFNet methods with memory management
    await PDFNet.runWithCleanup(async () => {

      // lock the document before a write operation
      // runWithCleanup will auto unlock when complete
      doc.lock();
      const s = 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.
      //s.setAsAnnotation(true); 

      await s.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 s.setFont(font);
      const redColorPt = await PDFNet.ColorPt.init(1, 0, 0, 0);
      await s.setFontColor(redColorPt);
      await s.setTextAlignment(PDFNet.Stamper.TextAlignment.e_align_right);
      await s.setAsBackground(false);
      const pgSet = await PDFNet.PageSet.createRange(1, 2);
      await s.stampText(doc, 'This is a title!', pgSet);

      const img = await PDFNet.Image.createFromURL(doc, imageName);
      s.setAsBackground(false);
      const pgSetImage = await PDFNet.PageSet.createRange(1, 1);
      await s.setAlignment(PDFNet.Stamper.HorizontalAlignment.e_horizontal_right, PDFNet.Stamper.VerticalAlignment.e_vertical_bottom);
      await s.stampImage(doc, img, pgSetImage);

      const srcDoc = await PDFNet.PDFDoc.createFromURL(fileName);
      const srcPage = await srcDoc.getPage(1);
      await s.setAlignment(PDFNet.Stamper.HorizontalAlignment.e_horizontal_left, PDFNet.Stamper.VerticalAlignment.e_vertical_bottom);
      await s.stampPage(doc, srcPage, pgSet);
    });

    // clear the cache (rendered) data with the newly updated document
    documentViewer.refreshAll();

    // Update viewer to render with the new document
    documentViewer.updateView();

    // Refresh searchable and selectable text data with the new document
    documentViewer.getDocument().refreshTextData();
  });
})
```

{% endcode %}

[WebViewerInstance](https://sdk.apryse.com/api/web/WebViewerInstance.html) [PDFNet.Stamper.create](https://sdk.apryse.com/api/web/Core.PDFNet.Stamper.html#.create__anchor) [PDFDoc.createFromURL](https://sdk.apryse.com/api/web/Core.PDFNet.PDFDoc.html#.createFromURL__anchor) [PDFNet.Image.createFromURL](https://sdk.apryse.com/api/web/Core.PDFNet.Image.html#.createFromURL__anchor) [PDFNet.Stamper.setSize](https://sdk.apryse.com/api/web/Core.PDFNet.Stamper.html#setSize__anchor) [PDFNet.Stamper.setAlignment](https://sdk.apryse.com/api/web/Core.PDFNet.Stamper.html#setAlignment__anchor) [PDFNet.Stamper.setFontColor](https://sdk.apryse.com/api/web/Core.PDFNet.Stamper.html#setFontColor__anchor) [PDFNet.Stamper.setRotation](https://sdk.apryse.com/api/web/Core.PDFNet.Stamper.html#setRotation__anchor) [PDFNet.Stamper.setAsAnnotation](https://sdk.apryse.com/api/web/Core.PDFNet.Stamper.html#setAsAnnotation__anchor) [PDFNet.PageSet.createRange](https://sdk.apryse.com/api/web/Core.PDFNet.PageSet.html#.createRange__anchor) [PDFNet.Stamper.stampImage](https://sdk.apryse.com/api/web/Core.PDFNet.Stamper.html#stampImage__anchor) [PDFNet.Stamper.stampText](https://sdk.apryse.com/api/web/Core.PDFNet.Stamper.html#stampText__anchor) [PDFNet.Stamper.stampPage](https://sdk.apryse.com/api/web/Core.PDFNet.Stamper.html#stampPage__anchor)
{% endtab %}

{% tab title="JavaScript (SDK v6.0+)" %}
{% code lineNumbers="true" %}

```js
let imageName = 'path to your image file';
let fileName = 'path to your PDF file';

WebViewer({
  fullAPI: true,
  // other constructor options
}, viewerElement).then(instance => {
  const { docViewer, PDFNet } = instance;

  document.getElementById('myBtn').addEventListener('click', async () => {
    await PDFNet.initialize();
    const doc = await docViewer.getDocument().getPDFDoc();

    // Run PDFNet methods with memory management
    await PDFNet.runWithCleanup(async () => {

      // lock the document before a write operation
      // runWithCleanup will auto unlock when complete
      doc.lock();
      const s = 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.
      //s.setAsAnnotation(true); 

      await s.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 s.setFont(font);
      const redColorPt = await PDFNet.ColorPt.init(1, 0, 0, 0);
      await s.setFontColor(redColorPt);
      await s.setTextAlignment(PDFNet.Stamper.TextAlignment.e_align_right);
      await s.setAsBackground(false);
      const pgSet = await PDFNet.PageSet.createRange(1, 2);
      await s.stampText(doc, 'This is a title!', pgSet);

      const img = await PDFNet.Image.createFromURL(doc, imageName);
      s.setAsBackground(false);
      const pgSetImage = await PDFNet.PageSet.createRange(1, 1);
      await s.setAlignment(PDFNet.Stamper.HorizontalAlignment.e_horizontal_right, PDFNet.Stamper.VerticalAlignment.e_vertical_bottom);
      await s.stampImage(doc, img, pgSetImage);

      const srcDoc = await PDFNet.PDFDoc.createFromURL(fileName);
      const srcPage = await srcDoc.getPage(1);
      await s.setAlignment(PDFNet.Stamper.HorizontalAlignment.e_horizontal_left, PDFNet.Stamper.VerticalAlignment.e_vertical_bottom);
      await s.stampPage(doc, srcPage, pgSet);
    });

    // clear the cache (rendered) data with the newly updated document
    docViewer.refreshAll();

    // Update viewer to render with the new document
    docViewer.updateView();

    // Refresh searchable and selectable text data with the new document
    docViewer.getDocument().refreshTextData();
  });
})
```

{% endcode %}

[WebViewerInstance](https://sdk.apryse.com/api/web/WebViewerInstance.html) [PDFNet.Stamper.create](https://sdk.apryse.com/api/web/Core.PDFNet.Stamper.html#.create__anchor) [PDFDoc.createFromURL](https://sdk.apryse.com/api/web/Core.PDFNet.PDFDoc.html#.createFromURL__anchor) [PDFNet.Image.createFromURL](https://sdk.apryse.com/api/web/Core.PDFNet.Image.html#.createFromURL__anchor) [PDFNet.Stamper.setSize](https://sdk.apryse.com/api/web/Core.PDFNet.Stamper.html#setSize__anchor) [PDFNet.Stamper.setAlignment](https://sdk.apryse.com/api/web/Core.PDFNet.Stamper.html#setAlignment__anchor) [PDFNet.Stamper.setFontColor](https://sdk.apryse.com/api/web/Core.PDFNet.Stamper.html#setFontColor__anchor) [PDFNet.Stamper.setRotation](https://sdk.apryse.com/api/web/Core.PDFNet.Stamper.html#setRotation__anchor) [PDFNet.Stamper.setAsAnnotation](https://sdk.apryse.com/api/web/Core.PDFNet.Stamper.html#setAsAnnotation__anchor) [PDFNet.PageSet.createRange](https://sdk.apryse.com/api/web/Core.PDFNet.PageSet.html#.createRange__anchor) [PDFNet.Stamper.stampImage](https://sdk.apryse.com/api/web/Core.PDFNet.Stamper.html#stampImage__anchor) [PDFNet.Stamper.stampText](https://sdk.apryse.com/api/web/Core.PDFNet.Stamper.html#stampText__anchor) [PDFNet.Stamper.stampPage](https://sdk.apryse.com/api/web/Core.PDFNet.Stamper.html#stampPage__anchor)
{% endtab %}
{% endtabs %}

[Stamp a PDF File](/web/get-started/samples.md#stamper) 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](/web/get-started/samples.md#elementbuilder).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.apryse.com/web/edit-page-content/stamp.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
