> 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/core/get-started/samples/stampertest.md).

# PDF Stamp / Watermark - Stamper

Sample code for using Apryse SDK to programmatically stamp PDF pages with text, images, or with other PDF pages.

{% hint style="info" %}
**Requirements**

*These packages are required to use these features in production. Trial keys have unlimited access to all features*

<a href="https://apryse.com/capabilities#Security" class="button primary">Package: Security</a><a href="https://showcase.apryse.com/add-watermark" class="button primary">Live demo</a>
{% endhint %}

Sample code for using Apryse SDK to programmatically stamp PDF pages with text, images. ElementBuilder and ElementWriter should be used for more complex PDF stamping operations.

Learn more about our [Server SDK](/core/get-started/frameworks/dotnet.md).

### **Implementation steps**

To add watermark to files with Apryse Server SDK:

Step 1: Follow [get started with Server SDK in your preferred language or framework](/core/get-started/get-started.md) Step 2: Add the sample code provided in this guide

To use this feature in production, your license key will need the [Security Package](https://apryse.com/capabilities#Security). Trial keys already include all packages.

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

using System;
using System.IO;

using pdftron;
using pdftron.Common;
using pdftron.Filters;
using pdftron.SDF;
using pdftron.PDF;

namespace PDFNetSamples
{
	class StamperSample
	{
		private static pdftron.PDFNetLoader pdfNetLoader = pdftron.PDFNetLoader.Instance();
		static StamperSample() {}
		
		/// <summary>
		// The following sample shows how to add new content (or watermark) PDF pages
		// using 'pdftron.PDF.Stamper' utility class. 
		//
		// Stamper can be used to 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.
		/// </summary>
		static void Main(string[] args)
		{
			PDFNet.Initialize(PDFTronLicense.Key);

			string input_path = "../../../../TestFiles/";
			string output_path = "../../../../TestFiles/Output/";
			string input_filename = "newsletter";

			//--------------------------------------------------------------------------------
			// Example 1) Add text stamp to all pages, then remove text stamp from odd pages. 
			try
			{
				using (PDFDoc doc = new PDFDoc(input_path + input_filename + ".pdf"))
				using (Stamper s = new Stamper(Stamper.SizeType.e_relative_scale, 0.5, 0.5))
				{
					doc.InitSecurityHandler();

					s.SetAlignment(Stamper.HorizontalAlignment.e_horizontal_center, Stamper.VerticalAlignment.e_vertical_center);
					s.SetFontColor(new ColorPt(1, 0, 0)); // set text color to red                
					s.StampText(doc, "If you are reading this\nthis is an even page", new PageSet(1, doc.GetPageCount()));
					//delete all text stamps in odd pages
					Stamper.DeleteStamps(doc, new PageSet(1, doc.GetPageCount(), PageSet.Filter.e_odd));

					doc.Save(output_path + input_filename + ".ex1.pdf", SDFDoc.SaveOptions.e_linearized);
				}
			}
			catch (PDFNetException e)
			{
				Console.WriteLine(e.Message);
			}

			//--------------------------------------------------------------------------------
			// Example 2) Add Image stamp to first 2 pages. 
			try
			{
				using (PDFDoc doc = new PDFDoc(input_path + input_filename + ".pdf"))
				using (Stamper s = new Stamper(Stamper.SizeType.e_relative_scale, .05, .05))
				{
					doc.InitSecurityHandler();

					Image img = Image.Create(doc, input_path + "peppers.jpg");
					s.SetSize(Stamper.SizeType.e_relative_scale, 0.5, 0.5);
					//set position of the image to the center, left of PDF pages
					s.SetAlignment(Stamper.HorizontalAlignment.e_horizontal_left, Stamper.VerticalAlignment.e_vertical_center);
					s.SetFontColor(new ColorPt(0, 0, 0, 0));
					s.SetRotation(180);
					s.SetAsBackground(false);
					//only stamp first 2 pages
					s.StampImage(doc, img, new PageSet(1, 2));

					doc.Save(output_path + input_filename + ".ex2.pdf", SDFDoc.SaveOptions.e_linearized);
				}
			}
			catch (PDFNetException e)
			{
				Console.WriteLine(e.Message);
			}

			//--------------------------------------------------------------------------------
			// Example 3) Add Page stamp to all pages. 
			try
			{
				using (PDFDoc doc = new PDFDoc(input_path + input_filename + ".pdf"))
				using (PDFDoc fish_doc = new PDFDoc(input_path + "fish.pdf"))
				using (Stamper s = new Stamper(Stamper.SizeType.e_relative_scale, .5, .5))
				{
					doc.InitSecurityHandler();

					fish_doc.InitSecurityHandler();

					Page src_page = fish_doc.GetPage(1);
					Rect page_one_crop = src_page.GetCropBox();
					// set size of the image to 10% of the original while keep the old aspect ratio
					s.SetSize(Stamper.SizeType.e_absolute_size, page_one_crop.Width() * 0.1, -1);
					s.SetOpacity(0.4);
					s.SetRotation(-67);
					//put the image at the bottom right hand corner
					s.SetAlignment(Stamper.HorizontalAlignment.e_horizontal_right, Stamper.VerticalAlignment.e_vertical_bottom);
					s.StampPage(doc, src_page, new PageSet(1, doc.GetPageCount()));

					doc.Save(output_path + input_filename + ".ex3.pdf", SDFDoc.SaveOptions.e_linearized);
				}
			}
			catch (PDFNetException e)
			{
				Console.WriteLine(e.Message);
			}

			//--------------------------------------------------------------------------------
			// Example 4) Add Image stamp to first 20 odd pages. 
			try
			{
				using (PDFDoc doc = new PDFDoc(input_path + input_filename + ".pdf"))
				using (Stamper s = new Stamper(Stamper.SizeType.e_absolute_size, 20, 20))
				{
					doc.InitSecurityHandler();

					s.SetOpacity(1);
					s.SetRotation(45);
					s.SetAsBackground(true);
					s.SetPosition(30, 40);
					Image img = Image.Create(doc, input_path + "peppers.jpg");
					s.StampImage(doc, img, new PageSet(1, 20, PageSet.Filter.e_odd));

					doc.Save(output_path + input_filename + ".ex4.pdf", SDFDoc.SaveOptions.e_linearized);
				}
			}
			catch (PDFNetException e)
			{
				Console.WriteLine(e.Message);
			}

			//--------------------------------------------------------------------------------
			// Example 5) Add text stamp to first 20 even pages
			try
			{
				using (PDFDoc doc = new PDFDoc(input_path + input_filename + ".pdf"))
				using (Stamper s = new Stamper(Stamper.SizeType.e_relative_scale, .05, .05))
				{
					doc.InitSecurityHandler();

					s.SetPosition(0, 0);
					s.SetOpacity(0.7);
					s.SetRotation(90);
					s.SetSize(Stamper.SizeType.e_font_size, 80, -1);
					s.SetTextAlignment(Stamper.TextAlignment.e_align_center);
					s.StampText(doc, "Goodbye\nMoon", new PageSet(1, 20, PageSet.Filter.e_even));

					doc.Save(output_path + input_filename + ".ex5.pdf", SDFDoc.SaveOptions.e_linearized);
				}
			}
			catch (PDFNetException e)
			{
				Console.WriteLine(e.Message);
			}

			//--------------------------------------------------------------------------------
			// Example 6) Add first page as stamp to all even pages
			try
			{
				using (PDFDoc doc = new PDFDoc(input_path + input_filename + ".pdf"))
				using (PDFDoc fish_doc = new PDFDoc(input_path + "fish.pdf"))
				using (Stamper s = new Stamper(Stamper.SizeType.e_relative_scale, .3, .3))
				{
					doc.InitSecurityHandler();

					fish_doc.InitSecurityHandler();

					s.SetOpacity(1);
					s.SetRotation(270);
					s.SetAsBackground(true);
					s.SetPosition(0.5, 0.5, true);
					s.SetAlignment(Stamper.HorizontalAlignment.e_horizontal_left, Stamper.VerticalAlignment.e_vertical_bottom);
					Page page_one = fish_doc.GetPage(1);
					s.StampPage(doc, page_one, new PageSet(1, doc.GetPageCount(), PageSet.Filter.e_even));

					doc.Save(output_path + input_filename + ".ex6.pdf", SDFDoc.SaveOptions.e_linearized);
				}
			}
			catch (PDFNetException e)
			{
				Console.WriteLine(e.Message);
			}

			//--------------------------------------------------------------------------------
			// Example 7) Add image stamp at top right corner in every pages
			try
			{
				using (PDFDoc doc = new PDFDoc(input_path + input_filename + ".pdf"))
				using (Stamper s = new Stamper(Stamper.SizeType.e_relative_scale, .1, .1))
				{
					doc.InitSecurityHandler();

					s.SetOpacity(0.8);
					s.SetRotation(135);
					s.SetAsBackground(false);
					s.ShowsOnPrint(false);
					s.SetAlignment(Stamper.HorizontalAlignment.e_horizontal_left, Stamper.VerticalAlignment.e_vertical_top);
					s.SetPosition(10, 10);

					Image img = Image.Create(doc, input_path + "peppers.jpg");
					s.StampImage(doc, img, new PageSet(1, doc.GetPageCount(), PageSet.Filter.e_all));

					doc.Save(output_path + input_filename + ".ex7.pdf", SDFDoc.SaveOptions.e_linearized);
				}
			}
			catch (PDFNetException e)
			{
				Console.WriteLine(e.Message);
			}

			//--------------------------------------------------------------------------------
			// Example 8) Add Text stamp to first 2 pages, and image stamp to first page.
			//          Because text stamp is set as background, the image is top of the text
			//          stamp. Text stamp on the first page is not visible.
			try
			{
				using (PDFDoc doc = new PDFDoc(input_path + input_filename + ".pdf"))
				using (Stamper s = new Stamper(Stamper.SizeType.e_relative_scale, 0.07, -0.1))
				{
					doc.InitSecurityHandler();

					s.SetAlignment(Stamper.HorizontalAlignment.e_horizontal_right, Stamper.VerticalAlignment.e_vertical_bottom);
					s.SetAlignment(Stamper.HorizontalAlignment.e_horizontal_center, Stamper.VerticalAlignment.e_vertical_top);
					s.SetFont(Font.Create(doc, Font.StandardType1Font.e_courier, true));
					s.SetFontColor(new ColorPt(1, 0, 0, 0)); //set color to red
					s.SetTextAlignment(Stamper.TextAlignment.e_align_right);
					s.SetAsBackground(true); //set text stamp as background
					s.StampText(doc, "This is a title!", new PageSet(1, 2));

					Image img = Image.Create(doc, input_path + "peppers.jpg");
					s.SetAsBackground(false); // set image stamp as foreground
					s.StampImage(doc, img, new PageSet(1));

					doc.Save(output_path + input_filename + ".ex8.pdf", SDFDoc.SaveOptions.e_linearized);
				}
			}
			catch (PDFNetException e)
			{
				Console.WriteLine(e.Message);
			}
			PDFNet.Terminate();
		}
	}
}
```

{% endcode %}
{% endtab %}

{% tab title="C++" %}
{% code lineNumbers="true" %}

```cpp
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

#include <PDF/PDFNet.h>
#include <PDF/PDFDoc.h>
#include <PDF/PageSet.h>
#include <PDF/Stamper.h>
#include <PDF/Image.h>
#include <iostream>
#include "../../LicenseKey/CPP/LicenseKey.h"

using namespace std;
using namespace pdftron;
using namespace Common;
using namespace SDF;
using namespace PDF;

//---------------------------------------------------------------------------------------
// The following sample shows how to add new content (or watermark) PDF pages
// using 'pdftron.PDF.Stamper' utility class. 
//
// Stamper can be used to 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.
//---------------------------------------------------------------------------------------
int main(int argc, char * argv[])
{
	int ret = 0;
	std::string input_path = "../../TestFiles/";
	std::string output_path = "../../TestFiles/Output/";
	std::string input_filename = "newsletter";	

	PDFNet::Initialize(LicenseKey);

	//--------------------------------------------------------------------------------
	// Example 1) Add text stamp to all pages, then remove text stamp from odd pages. 
	try
	{
		pdftron::PDF::PDFDoc doc((input_path + input_filename + ".pdf").c_str());
		doc.InitSecurityHandler();
		Stamper s(pdftron::PDF::Stamper::e_relative_scale, 0.5, 0.5);		

		s.SetAlignment(Stamper::e_horizontal_center, Stamper::e_vertical_center);
		ColorPt red(1, 0, 0); // set text color to red
		s.SetFontColor(red);
		s.StampText(doc, "If you are reading this\nthis is an even page", PageSet(1, doc.GetPageCount()));
		//delete all text stamps in even pages
		Stamper::DeleteStamps(doc, PageSet(1, doc.GetPageCount(), PageSet::e_odd));

		doc.Save(output_path + input_filename + ".ex1.pdf", SDFDoc::e_linearized, NULL);
	}
	catch (Common::Exception& e)
	{
		std::cout << e << endl;
		ret = 1;		
	}
	catch (...)
	{
		cout << "Unknown Exception" << endl;
		ret = 1;
	}

	//--------------------------------------------------------------------------------
	// Example 2) Add Image stamp to first 2 pages. 
	try
	{
		PDFDoc doc(input_path + input_filename + ".pdf");
		doc.InitSecurityHandler();

		Stamper s(Stamper::e_relative_scale, .05, .05);
		Image img = Image::Create(doc, input_path + "peppers.jpg");
		s.SetSize(Stamper::e_relative_scale, 0.5, 0.5);
		//set position of the image to the center, left of PDF pages
		s.SetAlignment(Stamper::e_horizontal_left, Stamper::e_vertical_center);
		ColorPt pt(0, 0, 0, 0);
		s.SetFontColor(pt);
		s.SetRotation(180);
		s.SetAsBackground(false);
		//only stamp first 2 pages
		PageSet ps(1, 2);
		s.StampImage(doc, img, ps);

		doc.Save(output_path + input_filename + ".ex2.pdf", SDFDoc::e_linearized, NULL);
	}
	catch (Common::Exception& e)
	{
		std::cout << e << endl;
		ret = 1;		
	}
	catch (...)
	{
		cout << "Unknown Exception" << endl;
		ret = 1;
	}

	//--------------------------------------------------------------------------------
	// Example 3) Add Page stamp to all pages. 
	try
	{
		PDFDoc doc(input_path + input_filename + ".pdf");
		doc.InitSecurityHandler();

		PDFDoc fish_doc(input_path + "fish.pdf");
		fish_doc.InitSecurityHandler();

		Stamper s(Stamper::e_relative_scale, 0.5, 0.5);
		Page src_page = fish_doc.GetPage(1);		 
		Rect page_one_crop = src_page.GetCropBox();
		// set size of the image to 10% of the original while keep the old aspect ratio
		s.SetSize(Stamper::e_absolute_size, page_one_crop.Width() * 0.1, -1);
		s.SetOpacity(0.4);
		s.SetRotation(-67);
		//put the image at the bottom right hand corner
		s.SetAlignment(Stamper::e_horizontal_right, Stamper::e_vertical_bottom);
		PageSet ps(1, doc.GetPageCount());
		s.StampPage(doc, src_page, ps);

		doc.Save(output_path + input_filename + ".ex3.pdf", SDFDoc::e_linearized, NULL);
	}
	catch (Common::Exception& e)
	{
		std::cout << e << endl;
		ret = 1;		
	}
	catch (...)
	{
		cout << "Unknown Exception" << endl;
		ret = 1;
	}

	//--------------------------------------------------------------------------------
	// Example 4) Add Image stamp to first 20 odd pages.
	try
	{
		PDFDoc doc(input_path + input_filename + ".pdf");
		doc.InitSecurityHandler();

		Stamper s(Stamper::e_absolute_size, 20, 20);
		s.SetOpacity(1);
		s.SetRotation(45);                
		s.SetAsBackground(true);
		s.SetPosition(30, 40);
		Image img = Image::Create(doc, input_path + "peppers.jpg");
		PageSet ps(1, 20, PageSet::e_odd);
		s.StampImage(doc, img, ps);

		doc.Save(output_path + input_filename + ".ex4.pdf", SDFDoc::e_linearized, NULL);
	}
	catch (Common::Exception& e)
	{
		std::cout << e << endl;
		ret = 1;		
	}
	catch (...)
	{
		cout << "Unknown Exception" << endl;
		ret = 1;
	}

	//--------------------------------------------------------------------------------
	// Example 5) Add text stamp to first 20 even pages
	try
	{
		PDFDoc doc(input_path + input_filename + ".pdf");
		doc.InitSecurityHandler();

		Stamper s(Stamper::e_relative_scale, .05, .05);
		s.SetPosition(0, 0);
		s.SetOpacity(0.7);
		s.SetRotation(90);
		s.SetSize(Stamper::e_font_size, 80, -1);
		s.SetTextAlignment(Stamper::e_align_center);
		PageSet ps(1, 20, PageSet::e_even);
		s.StampText(doc, "Goodbye\nMoon", ps);

		doc.Save(output_path + input_filename + ".ex5.pdf", SDFDoc::e_linearized, NULL);
	}
	catch (Common::Exception& e)
	{
		std::cout << e << endl;
		ret = 1;		
	}
	catch (...)
	{
		cout << "Unknown Exception" << endl;
		ret = 1;
	}

	//--------------------------------------------------------------------------------
	// Example 6) Add first page as stamp to all even pages
	try
	{
		PDFDoc doc(input_path + input_filename + ".pdf");
		doc.InitSecurityHandler();

		PDFDoc fish_doc(input_path + "fish.pdf");
		fish_doc.InitSecurityHandler();

		Stamper s(Stamper::e_relative_scale, .3, .3);
		s.SetOpacity(1);                
		s.SetRotation(270);
		s.SetAsBackground(true);
		s.SetPosition(0.5, 0.5, true);
		s.SetAlignment(Stamper::e_horizontal_left, Stamper::e_vertical_bottom);
		Page page_one = fish_doc.GetPage(1);
		PageSet ps(1, doc.GetPageCount(), PageSet::e_even);
		s.StampPage(doc, page_one, ps);

		doc.Save(output_path + input_filename + ".ex6.pdf", SDFDoc::e_linearized, NULL);
	}
	catch (Common::Exception& e)
	{
		std::cout << e << endl;
		ret = 1;		
	}
	catch (...)
	{
		cout << "Unknown Exception" << endl;
		ret = 1;
	}

	//--------------------------------------------------------------------------------
	// Example 7) Add image stamp at top right corner in every pages
	try
	{
		PDFDoc doc(input_path + input_filename + ".pdf");
		doc.InitSecurityHandler();

		Stamper s(Stamper::e_relative_scale, .1, .1);
		s.SetOpacity(0.8);
		s.SetRotation(135);
		s.SetAsBackground(false);
		s.ShowsOnPrint(false);
		s.SetAlignment(Stamper::e_horizontal_left, Stamper::e_vertical_top);
		s.SetPosition(10, 10);

		Image img = Image::Create(doc, input_path + "peppers.jpg");
		PageSet ps(1, doc.GetPageCount(), PageSet::e_all);
		s.StampImage(doc, img, ps);

		doc.Save(output_path + input_filename + ".ex7.pdf", SDFDoc::e_linearized, NULL);
	}
	catch (Common::Exception& e)
	{
		std::cout << e << endl;
		ret = 1;		
	}
	catch (...)
	{
		cout << "Unknown Exception" << endl;
		ret = 1;
	}

	//--------------------------------------------------------------------------------
	// Example 8) Add Text stamp to first 2 pages, and image stamp to first page.
	//          Because text stamp is set as background, the image is top of the text
	//          stamp. Text stamp on the first page is not visible.
	try
	{
		PDFDoc doc(input_path + input_filename + ".pdf");
		doc.InitSecurityHandler();

		Stamper s(Stamper::e_relative_scale, 0.07, -0.1);
		s.SetAlignment(Stamper::e_horizontal_right, Stamper::e_vertical_bottom);
		s.SetAlignment(Stamper::e_horizontal_center, Stamper::e_vertical_top);
		s.SetFont(Font::Create(doc, Font::e_courier, true));
		ColorPt red(1, 0, 0, 0);
		s.SetFontColor(red); //set color to red
		s.SetTextAlignment(Stamper::e_align_right);
		s.SetAsBackground(true); //set text stamp as background
		PageSet ps(1, 2);
		s.StampText(doc, "This is a title!", ps);

		Image img = Image::Create(doc, input_path + "peppers.jpg");
		s.SetAsBackground(false); // set image stamp as foreground
		PageSet first_page_ps(1);
		s.StampImage(doc, img, first_page_ps);

		doc.Save(output_path + input_filename + ".ex8.pdf", SDFDoc::e_linearized, NULL);
	}
	catch (Common::Exception& e)
	{
		std::cout << e << endl;
		ret = 1;		
	}
	catch (...)
	{
		cout << "Unknown Exception" << endl;
		ret = 1;
	}

	PDFNet::Terminate();
	return ret;
}
```

{% endcode %}
{% endtab %}

{% tab title="Go" %}
{% code lineNumbers="true" %}

```go
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.
// Consult LICENSE.txt regarding license information.
//---------------------------------------------------------------------------------------

package main
import (
    . "pdftron"
)

import  "pdftron/Samples/LicenseKey/GO"
//---------------------------------------------------------------------------------------
// The following sample shows how to add new content (or watermark) PDF pages
// using 'pdftron.PDF.Stamper' utility class. 
//
// Stamper can be used to 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.
//---------------------------------------------------------------------------------------

// Relative path to the folder containing the test files.
var inputPath = "../../TestFiles/"
var outputPath = "../../TestFiles/Output/"
var inputFilename = "newsletter"

func main(){
    // Initialize PDFNet
    PDFNetInitialize(PDFTronLicense.Key)
    
    //--------------------------------------------------------------------------------
    // Example 1) Add text stamp to all pages, then remove text stamp from odd pages. 
    doc := NewPDFDoc(inputPath + inputFilename + ".pdf")
    doc.InitSecurityHandler()
    s := NewStamper(StamperE_relative_scale, 0.5, 0.5)
    
    s.SetAlignment(StamperE_horizontal_center, StamperE_vertical_center)
    red := NewColorPt(1.0, 0.0, 0.0) // set text color to red
    s.SetFontColor(red)
    s.StampText(doc, "If you are reading this\nthis is an even page", NewPageSet(1, doc.GetPageCount()))
    // delete all text stamps in odd pages
    StamperDeleteStamps(doc, NewPageSet(1, doc.GetPageCount(), PageSetE_odd))
    
    doc.Save(outputPath + inputFilename + "E_x1.pdf", uint(SDFDocE_linearized))
    doc.Close()

    //--------------------------------------------------------------------------------
    // Example 2) Add Image stamp to first 2 pages. 
    
    doc = NewPDFDoc(inputPath + inputFilename + ".pdf")
    doc.InitSecurityHandler()
    s = NewStamper(StamperE_relative_scale, 0.05, 0.05)
    img := ImageCreate(doc.GetSDFDoc(), inputPath + "peppers.jpg")
    s.SetSize(StamperE_relative_scale, 0.5, 0.5)
    
    // set position of the image to the center, left of PDF pages
    s.SetAlignment(StamperE_horizontal_left, StamperE_vertical_center)
    pt := NewColorPt(0.0, 0.0, 0.0, 0.0)
    s.SetFontColor(pt)
    s.SetRotation(180)
    s.SetAsBackground(false)
    // only stamp first 2 pages
    ps := NewPageSet(1, 2)
    s.StampImage(doc, img, ps)
    
    doc.Save(outputPath + inputFilename + "E_x2.pdf", uint(SDFDocE_linearized))
    doc.Close()
    
    //--------------------------------------------------------------------------------
    // Example 3) Add Page stamp to all pages. 
    
    doc = NewPDFDoc(inputPath + inputFilename + ".pdf")
    doc.InitSecurityHandler()
    
    fishDoc := NewPDFDoc(inputPath + "fish.pdf")
    fishDoc.InitSecurityHandler()
    s = NewStamper(StamperE_relative_scale, 0.5, 0.5)
    srcPage := fishDoc.GetPage(1)
    pageOneCrop := srcPage.GetCropBox()
    // set size of the image to 10% of the original while keep the old aspect ratio
    s.SetSize(StamperE_absolute_size, pageOneCrop.Width() * 0.1, -1)
    s.SetOpacity(0.4)
    s.SetRotation(-67)
    // put the image at the bottom right hand corner
    s.SetAlignment(StamperE_horizontal_right, StamperE_vertical_bottom)
    ps = NewPageSet(1, doc.GetPageCount())
    s.StampPage(doc, srcPage, ps)
    doc.Save(outputPath + inputFilename + "E_x3.pdf", uint(SDFDocE_linearized))
    doc.Close()
    
    //--------------------------------------------------------------------------------
    // Example 4) Add Image stamp to first 20 odd pages.
    
    doc = NewPDFDoc(inputPath + inputFilename + ".pdf")
    doc.InitSecurityHandler()
    
    s = NewStamper(StamperE_absolute_size, 20.0, 20.0)
    s.SetOpacity(1)
    s.SetRotation(45)
    s.SetAsBackground(true)
    s.SetPosition(30.0, 40.0)
    img = ImageCreate(doc.GetSDFDoc(), inputPath + "peppers.jpg")
    ps = NewPageSet(1, 20, PageSetE_odd)
    s.StampImage(doc, img, ps)
    
    doc.Save(outputPath + inputFilename + "E_x4.pdf", uint(SDFDocE_linearized))
    doc.Close()
    
    //--------------------------------------------------------------------------------
    // Example 5) Add text stamp to first 20 even pages
    
    doc = NewPDFDoc(inputPath + inputFilename + ".pdf")
    doc.InitSecurityHandler()
    s = NewStamper(StamperE_relative_scale, 0.05, 0.05)
    s.SetPosition(0.0, 0.0)
    s.SetOpacity(0.7)
    s.SetRotation(90)
    s.SetSize(StamperE_font_size, 80, -1)
    s.SetTextAlignment(StamperE_align_center)
    ps = NewPageSet(1, 20, PageSetE_even)
    s.StampText(doc, "Goodbye\nMoon", ps)
    
    doc.Save(outputPath + inputFilename + "E_x5.pdf", uint(SDFDocE_linearized))
    doc.Close()
    
    //--------------------------------------------------------------------------------
    // Example 6) Add first page as stamp to all even pages
    
    doc = NewPDFDoc(inputPath + inputFilename + ".pdf")
    doc.InitSecurityHandler()
    
    fishDoc = NewPDFDoc(inputPath + "fish.pdf");
    fishDoc.InitSecurityHandler()
    
    s = NewStamper(StamperE_relative_scale, 0.3, 0.3)
    s.SetOpacity(1)
    s.SetRotation(270)
    s.SetAsBackground(true)
    s.SetPosition(0.5, 0.5, true)
    s.SetAlignment(StamperE_horizontal_left, StamperE_vertical_bottom)
    pageOne := fishDoc.GetPage(1)
    ps = NewPageSet(1, doc.GetPageCount(), PageSetE_even)
    s.StampPage(doc, pageOne, ps)
    
    doc.Save(outputPath + inputFilename + "E_x6.pdf", uint(SDFDocE_linearized))
    doc.Close()
    
    //--------------------------------------------------------------------------------
    // Example 7) Add image stamp at top left corner in every pages
    
    doc = NewPDFDoc(inputPath + inputFilename + ".pdf")
    doc.InitSecurityHandler()
    
    s = NewStamper(StamperE_relative_scale, 0.1, 0.1)
    s.SetOpacity(0.8)
    s.SetRotation(135)
    s.SetAsBackground(false)
    s.ShowsOnPrint(false)
    s.SetAlignment(StamperE_horizontal_left, StamperE_vertical_top)
    s.SetPosition(10.0, 10.0)
    img = ImageCreate(doc.GetSDFDoc(), inputPath + "peppers.jpg")
    ps = NewPageSet(1, doc.GetPageCount(), PageSetE_all)
    s.StampImage(doc, img, ps)
    doc.Save(outputPath + inputFilename + "E_x7.pdf", uint(SDFDocE_linearized))
    doc.Close()
    
    //--------------------------------------------------------------------------------
    // Example 8) Add Text stamp to first 2 pages, and image stamp to first page.
    //          Because text stamp is set as background, the image is top of the text
    //          stamp. Text stamp on the first page is not visible.
    
    doc = NewPDFDoc(inputPath + inputFilename + ".pdf")
    doc.InitSecurityHandler()
    
    s = NewStamper(StamperE_relative_scale, 0.07, -0.1)
    s.SetAlignment(StamperE_horizontal_right, StamperE_vertical_bottom)
    s.SetAlignment(StamperE_horizontal_center, StamperE_vertical_top)
    s.SetFont(FontCreate(doc.GetSDFDoc(), FontE_courier, true))
    red = NewColorPt(1.0, 0.0, 0.0) 
    s.SetFontColor(red) // set text color to red
    s.SetTextAlignment(StamperE_align_right)
    s.SetAsBackground(true) // set text stamp as background
    ps = NewPageSet(1, 2)
    s.StampText(doc, "This is a title!", ps)
    
    img = ImageCreate(doc.GetSDFDoc(), inputPath + "peppers.jpg")
    s.SetAsBackground(false)    // set image stamp as foreground
    firstPagePS := NewPageSet(1)
    s.StampImage(doc, img, firstPagePS)

    doc.Save(outputPath + inputFilename + "E_x8.pdf", uint(SDFDocE_linearized))
    doc.Close()
    PDFNetTerminate()
}
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

import com.pdftron.pdf.*;
import com.pdftron.sdf.SDFDoc;

public class StamperTest {
    //---------------------------------------------------------------------------------------
    // The following sample shows how to add new content (or watermark) PDF pages
    // using 'pdftron.PDF.Stamper' utility class.
    //
    // Stamper can be used to 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.
    //---------------------------------------------------------------------------------------
    public static void main(String[] args) {
        String input_path = "../../TestFiles/";
        String output_path = "../../TestFiles/Output/";
        String input_filename = "newsletter";

        PDFNet.initialize(PDFTronLicense.Key());

        //--------------------------------------------------------------------------------
        // Example 1) Add text stamp to all pages, then remove text stamp from odd pages.
        try (PDFDoc doc = new PDFDoc(input_path + input_filename + ".pdf")) {
            doc.initSecurityHandler();
            Stamper s = new Stamper(Stamper.e_relative_scale, 0.5, 0.5);
            s.setAlignment(Stamper.e_horizontal_center, Stamper.e_vertical_center);
            ColorPt red = new ColorPt(1, 0, 0); // set text color to red
            s.setFontColor(red);
            String msg = "If you are reading this\nthis is an even page";
            PageSet ps = new PageSet(1, doc.getPageCount());
            s.stampText(doc, msg, ps);
            //delete all text stamps in even pages
            PageSet ps1 = new PageSet(1, doc.getPageCount(), PageSet.e_odd);
            Stamper.deleteStamps(doc, ps1);

            doc.save(output_path + input_filename + ".ex1.pdf", SDFDoc.SaveMode.LINEARIZED, null);
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }

        //--------------------------------------------------------------------------------
        // Example 2) Add Image stamp to first 2 pages.
        try (PDFDoc doc = new PDFDoc(input_path + input_filename + ".pdf")) {
            doc.initSecurityHandler();

            Stamper s = new Stamper(Stamper.e_relative_scale, .05, .05);
            Image img = Image.create(doc, input_path + "peppers.jpg");
            s.setSize(Stamper.e_relative_scale, 0.5, 0.5);
            //set position of the image to the center, left of PDF pages
            s.setAlignment(Stamper.e_horizontal_left, Stamper.e_vertical_center);
            ColorPt pt = new ColorPt(0, 0, 0, 0);
            s.setFontColor(pt);
            s.setRotation(180);
            s.setAsBackground(false);
            //only stamp first 2 pages
            PageSet ps = new PageSet(1, 2);
            s.stampImage(doc, img, ps);

            doc.save(output_path + input_filename + ".ex2.pdf", SDFDoc.SaveMode.LINEARIZED, null);
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }

        //--------------------------------------------------------------------------------
        // Example 3) Add Page stamp to all pages.
        try (PDFDoc doc = new PDFDoc(input_path + input_filename + ".pdf")) {
            doc.initSecurityHandler();

            try (PDFDoc fish_doc = new PDFDoc(input_path + "fish.pdf")) {
                fish_doc.initSecurityHandler();

                Stamper s = new Stamper(Stamper.e_relative_scale, 0.5, 0.5);
                Page src_page = fish_doc.getPage(1);
                Rect page_one_crop = src_page.getCropBox();
                // set size of the image to 10% of the original while keep the old aspect ratio
                s.setSize(Stamper.e_absolute_size, page_one_crop.getWidth() * 0.1, -1);
                s.setOpacity(0.4);
                s.setRotation(-67);
                //put the image at the bottom right hand corner
                s.setAlignment(Stamper.e_horizontal_right, Stamper.e_vertical_bottom);
                PageSet ps = new PageSet(1, doc.getPageCount());
                s.stampPage(doc, src_page, ps);

                doc.save(output_path + input_filename + ".ex3.pdf", SDFDoc.SaveMode.LINEARIZED, null);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }

        //--------------------------------------------------------------------------------
        // Example 4) Add Image stamp to first 20 odd pages.
        try (PDFDoc doc = new PDFDoc(input_path + input_filename + ".pdf")) {
            doc.initSecurityHandler();

            Stamper s = new Stamper(Stamper.e_absolute_size, 20, 20);
            s.setOpacity(1);
            s.setRotation(45);
            s.setAsBackground(true);
            s.setPosition(30, 40);
            Image img = Image.create(doc, input_path + "peppers.jpg");
            PageSet ps = new PageSet(1, 20, PageSet.e_odd);
            s.stampImage(doc, img, ps);

            doc.save(output_path + input_filename + ".ex4.pdf", SDFDoc.SaveMode.LINEARIZED, null);
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }

        //--------------------------------------------------------------------------------
        // Example 5) Add text stamp to first 20 even pages
        try (PDFDoc doc = new PDFDoc(input_path + input_filename + ".pdf")) {
            doc.initSecurityHandler();

            Stamper s = new Stamper(Stamper.e_relative_scale, .05, .05);
            s.setPosition(0, 0);
            s.setOpacity(0.7);
            s.setRotation(90);
            s.setSize(Stamper.e_font_size, 80, -1);
            s.setTextAlignment(Stamper.e_align_center);
            PageSet ps = new PageSet(1, 20, PageSet.e_even);
            s.stampText(doc, "Goodbye\nMoon", ps);

            doc.save(output_path + input_filename + ".ex5.pdf", SDFDoc.SaveMode.LINEARIZED, null);
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }

        //--------------------------------------------------------------------------------
        // Example 6) Add first page as stamp to all even pages
        try (PDFDoc doc = new PDFDoc(input_path + input_filename + ".pdf")) {
            doc.initSecurityHandler();

            PDFDoc fish_doc = new PDFDoc(input_path + "fish.pdf");
            fish_doc.initSecurityHandler();

            Stamper s = new Stamper(Stamper.e_relative_scale, 0.3, 0.3);
            s.setOpacity(1);
            s.setRotation(270);
            s.setAsBackground(true);
            s.setPosition(0.5, 0.5, true);
            s.setAlignment(Stamper.e_horizontal_left, Stamper.e_vertical_bottom);
            Page page_one = fish_doc.getPage(1);
            PageSet ps = new PageSet(1, doc.getPageCount(), PageSet.e_even);
            s.stampPage(doc, page_one, ps);

            doc.save(output_path + input_filename + ".ex6.pdf", SDFDoc.SaveMode.LINEARIZED, null);
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }

        //--------------------------------------------------------------------------------
        // Example 7) Add image stamp at top right corner in every pages
        try (PDFDoc doc = new PDFDoc(input_path + input_filename + ".pdf")) {
            doc.initSecurityHandler();

            Stamper s = new Stamper(Stamper.e_relative_scale, .1, .1);
            s.setOpacity(0.8);
            s.setRotation(135);
            s.setAsBackground(false);
            s.showsOnPrint(false);
            s.setAlignment(Stamper.e_horizontal_left, Stamper.e_vertical_top);
            s.setPosition(10, 10);

            Image img = Image.create(doc, input_path + "peppers.jpg");
            PageSet ps = new PageSet(1, doc.getPageCount(), PageSet.e_all);
            s.stampImage(doc, img, ps);

            doc.save(output_path + input_filename + ".ex7.pdf", SDFDoc.SaveMode.LINEARIZED, null);
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }

        //--------------------------------------------------------------------------------
        // Example 8) Add Text stamp to first 2 pages, and image stamp to first page.
        //          Because text stamp is set as background, the image is top of the text
        //          stamp. Text stamp on the first page is not visible.
        try (PDFDoc doc = new PDFDoc(input_path + input_filename + ".pdf")) {
            doc.initSecurityHandler();

            Stamper s = new Stamper(Stamper.e_relative_scale, 0.07, -0.1);
            s.setAlignment(Stamper.e_horizontal_right, Stamper.e_vertical_bottom);
            s.setAlignment(Stamper.e_horizontal_center, Stamper.e_vertical_top);
            s.setFont(Font.create(doc, Font.e_courier, true));
            ColorPt red = new ColorPt(1, 0, 0, 0);
            s.setFontColor(red); //set color to red
            s.setTextAlignment(Stamper.e_align_right);
            s.setAsBackground(true); //set text stamp as background
            PageSet ps = new PageSet(1, 2);
            s.stampText(doc, "This is a title!", ps);

            Image img = Image.create(doc, input_path + "peppers.jpg");
            s.setAsBackground(false); // set image stamp as foreground
            PageSet first_page_ps = new PageSet(1);
            s.stampImage(doc, img, first_page_ps);

            doc.save(output_path + input_filename + ".ex8.pdf", SDFDoc.SaveMode.LINEARIZED, null);
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }

        PDFNet.terminate();
    }
}
```

{% endcode %}
{% endtab %}

{% tab title="JavaScript" %}
{% code lineNumbers="true" %}

```js
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------
// The following sample shows how to add new content (or watermark) PDF pages
// using 'pdftron.PDF.Stamper' utility class. 
//
// Stamper can be used to 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.
//---------------------------------------------------------------------------------------

const { PDFNet } = require('@pdftron/pdfnet-node');
const PDFTronLicense = require('../LicenseKey/LicenseKey');

((exports) => {

  exports.runStamperTest = () => {

    const main = async () => {
      // Relative path to the folder containing test files.
      const inputPath = '../TestFiles/';
      const outputPath = inputPath + 'Output/';

      //--------------------------------------------------------------------------------
      // Example 1) Add text stamp to all pages, then remove text stamp from odd pages. 
      try {
        // start stack-based deallocation with startDeallocateStack. Later on when endDeallocateStack is called,
        // all objects in memory that were initialized since the most recent startDeallocateStack call will be
        // cleaned up. Doing this makes sure that memory growth does not get too high.
        await PDFNet.startDeallocateStack();

        const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'newsletter.pdf');
        doc.initSecurityHandler();

        const stamper = await PDFNet.Stamper.create(PDFNet.Stamper.SizeType.e_relative_scale, 0.5, 0.5); // Stamp size is relative to the size of the crop box of the destination page
        stamper.setAlignment(PDFNet.Stamper.HorizontalAlignment.e_horizontal_center, PDFNet.Stamper.VerticalAlignment.e_vertical_center);

        const redColorPt = await PDFNet.ColorPt.init(1, 0, 0);
        stamper.setFontColor(redColorPt);
        const pgSet = await PDFNet.PageSet.createRange(1, (await doc.getPageCount()));
        stamper.stampText(doc, 'If you are reading this\nthis is an even page', pgSet);
        const oddPgSet = await PDFNet.PageSet.createFilteredRange(1, (await doc.getPageCount()), PDFNet.PageSet.Filter.e_odd);
        // delete all text stamps in odd pages
        PDFNet.Stamper.deleteStamps(doc, oddPgSet);

        await doc.save(outputPath + 'newsletter.ex1.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);

        await PDFNet.endDeallocateStack();
      } catch (err) {
        console.log(err.stack);
      }

      //--------------------------------------------------------------------------------
      // Example 2) Add Image stamp to first 2 pages. 
      try {
        await PDFNet.startDeallocateStack();
        const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'newsletter.pdf');
        doc.initSecurityHandler();

        const stamper = await PDFNet.Stamper.create(PDFNet.Stamper.SizeType.e_relative_scale, 0.5, 0.5);
        const img = await PDFNet.Image.createFromFile(doc, inputPath + 'peppers.jpg');
        stamper.setSize(PDFNet.Stamper.SizeType.e_relative_scale, 0.5, 0.5);
        // set position of the image to the center, left of PDF pages
        stamper.setAlignment(PDFNet.Stamper.HorizontalAlignment.e_horizontal_left, PDFNet.Stamper.VerticalAlignment.e_vertical_center);

        const blackColorPt = await PDFNet.ColorPt.init(0, 0, 0, 0);
        stamper.setFontColor(blackColorPt);
        stamper.setRotation(180);
        stamper.setAsBackground(false);
        // only stamp first 2 pages
        const pgSet = await PDFNet.PageSet.createRange(1, 2);
        stamper.stampImage(doc, img, pgSet);

        await doc.save(outputPath + 'newsletter.ex2.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
        await PDFNet.endDeallocateStack();
      } catch (err) {
        console.log(err.stack);
      }

      //--------------------------------------------------------------------------------
      // Example 3) Add Page stamp to all pages. 
      try {
        await PDFNet.startDeallocateStack();
        const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'newsletter.pdf');
        doc.initSecurityHandler();
        const fishDoc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'fish.pdf');
        fishDoc.initSecurityHandler();

        const stamper = await PDFNet.Stamper.create(PDFNet.Stamper.SizeType.e_relative_scale, 0.5, 0.5);
        const srcPage = await fishDoc.getPage(1);
        const pageOneCrop = await srcPage.getCropBox();
        // set size of the image to 10% of the original while keep the old aspect ratio
        stamper.setSize(PDFNet.Stamper.SizeType.e_absolute_size, (await pageOneCrop.width()) * 0.1, -1);
        stamper.setOpacity(0.4);
        stamper.setRotation(-67);

        // put the image at the bottom right hand corner
        stamper.setAlignment(PDFNet.Stamper.HorizontalAlignment.e_horizontal_right, PDFNet.Stamper.VerticalAlignment.e_vertical_bottom);
        const pgSet = await PDFNet.PageSet.createRange(1, (await doc.getPageCount()));
        stamper.stampPage(doc, srcPage, pgSet);

        await doc.save(outputPath + 'newsletter.ex3.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
        await PDFNet.endDeallocateStack();
      } catch (err) {
        console.log(err.stack);
      }

      //--------------------------------------------------------------------------------
      // Example 4) Add Image stamp to first 20 odd pages.
      try {
        await PDFNet.startDeallocateStack();
        const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'newsletter.pdf');
        doc.initSecurityHandler();

        const stamper = await PDFNet.Stamper.create(PDFNet.Stamper.SizeType.e_absolute_size, 20, 20);
        stamper.setOpacity(1);
        stamper.setRotation(45);
        stamper.setAsBackground(true);
        stamper.setPosition(30, 40);
        const img = await PDFNet.Image.createFromFile(doc, inputPath + 'peppers.jpg');

        const pgSet = await PDFNet.PageSet.createFilteredRange(1, 20, PDFNet.PageSet.Filter.e_odd);
        stamper.stampImage(doc, img, pgSet);

        await doc.save(outputPath + 'newsletter.ex4.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
        await PDFNet.endDeallocateStack();
      } catch (err) {
        console.log(err.stack);
      }

      //--------------------------------------------------------------------------------
      // Example 5) Add text stamp to first 20 even pages
      try {
        await PDFNet.startDeallocateStack();

        const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'newsletter.pdf');
        doc.initSecurityHandler();

        const stamper = await PDFNet.Stamper.create(PDFNet.Stamper.SizeType.e_relative_scale, 0.05, 0.05);
        stamper.setPosition(0, 0);
        stamper.setOpacity(0.7);
        stamper.setRotation(90);
        stamper.setSize(PDFNet.Stamper.SizeType.e_font_size, 80, -1);
        stamper.setTextAlignment(PDFNet.Stamper.TextAlignment.e_align_center);
        const pgSet = await PDFNet.PageSet.createFilteredRange(1, 20, PDFNet.PageSet.Filter.e_even);
        stamper.stampText(doc, 'Goodbye\nMoon', pgSet);

        await doc.save(outputPath + 'newsletter.ex5.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);

        await PDFNet.endDeallocateStack();
      } catch (err) {
        console.log(err.stack);
      }

      //--------------------------------------------------------------------------------
      // Example 6) Add first page as stamp to all even pages
      try {
        await PDFNet.startDeallocateStack();

        const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'newsletter.pdf');
        doc.initSecurityHandler();

        const fishDoc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'fish.pdf');
        fishDoc.initSecurityHandler();

        const stamper = await PDFNet.Stamper.create(PDFNet.Stamper.SizeType.e_relative_scale, 0.3, 0.3);
        stamper.setOpacity(1);
        stamper.setRotation(270);
        stamper.setAsBackground(true);
        stamper.setPosition(0.5, 0.5, true);
        stamper.setAlignment(PDFNet.Stamper.HorizontalAlignment.e_horizontal_left, PDFNet.Stamper.VerticalAlignment.e_vertical_bottom);
        const pgOne = await fishDoc.getPage(1);
        const pgSet = await PDFNet.PageSet.createFilteredRange(1, await doc.getPageCount(), PDFNet.PageSet.Filter.e_even);
        stamper.stampPage(doc, pgOne, pgSet);

        await doc.save(outputPath + 'newsletter.ex6.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);

        await PDFNet.endDeallocateStack();
      } catch (err) {
        console.log(err.stack);
      }

      //--------------------------------------------------------------------------------
      // Example 7) Add image stamp at top right corner in every pages
      try {
        await PDFNet.startDeallocateStack();

        const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'newsletter.pdf');
        doc.initSecurityHandler();

        const stamper = await PDFNet.Stamper.create(PDFNet.Stamper.SizeType.e_relative_scale, 0.1, 0.1);
        stamper.setOpacity(0.8);
        stamper.setRotation(135);
        stamper.setAsBackground(false);
        stamper.showsOnPrint(false);
        stamper.setAlignment(PDFNet.Stamper.HorizontalAlignment.e_horizontal_left, PDFNet.Stamper.VerticalAlignment.e_vertical_top);
        stamper.setPosition(10, 10);

        const img = await PDFNet.Image.createFromFile(doc, inputPath + 'peppers.jpg');
        const pgSet = await PDFNet.PageSet.createFilteredRange(1, (await doc.getPageCount()), PDFNet.PageSet.Filter.e_all);
        stamper.stampImage(doc, img, pgSet);

        await doc.save(outputPath + 'newsletter.ex7.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);

        await PDFNet.endDeallocateStack();
      } catch (err) {
        console.log(err.stack);
      }

      //--------------------------------------------------------------------------------
      // Example 8) Add Text stamp to first 2 pages, and image stamp to first page.
      //          Because text stamp is set as background, the image is top of the text
      //          stamp. Text stamp on the first page is not visible.
      try {
        await PDFNet.startDeallocateStack();

        const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'newsletter.pdf');
        doc.initSecurityHandler();

        const stamper = await PDFNet.Stamper.create(PDFNet.Stamper.SizeType.e_relative_scale, 0.07, -0.1);
        stamper.setAlignment(PDFNet.Stamper.HorizontalAlignment.e_horizontal_right, PDFNet.Stamper.VerticalAlignment.e_vertical_bottom);
        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);
        stamper.setFont(font);
        const redColorPt = await PDFNet.ColorPt.init(1, 0, 0, 0);
        stamper.setFontColor(redColorPt);
        stamper.setTextAlignment(PDFNet.Stamper.TextAlignment.e_align_right);
        stamper.setAsBackground(true);

        const pgSet = await PDFNet.PageSet.createRange(1, 2);
        stamper.stampText(doc, 'This is a title!', pgSet);

        const img = await PDFNet.Image.createFromFile(doc, inputPath + 'peppers.jpg');
        stamper.setAsBackground(false);

        const pgSetImage = await PDFNet.PageSet.createRange(1, 1);
        stamper.stampImage(doc, img, pgSetImage);

        await doc.save(outputPath + 'newsletter.ex8.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);

        await PDFNet.endDeallocateStack();
      } catch (err) {
        console.log(err.stack);
      }
    };
    PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function (error) { console.log('Error: ' + JSON.stringify(error)); }).then(function () { return PDFNet.shutdown(); });
  };
  exports.runStamperTest();
})(exports);
// eslint-disable-next-line spaced-comment
//# sourceURL=StamperTest.js
```

{% endcode %}
{% endtab %}

{% tab title="PHP" %}
{% code lineNumbers="true" %}

```php
<?php
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
// Consult LICENSE.txt regarding license information.
//---------------------------------------------------------------------------------------
if(file_exists("../../../PDFNetC/Lib/PDFNetPHP.php"))
include("../../../PDFNetC/Lib/PDFNetPHP.php");
include("../../LicenseKey/PHP/LicenseKey.php");

// Relative path to the folder containing the test files.
$input_path = getcwd()."/../../TestFiles/";
$output_path = $input_path."Output/";
$input_filename = "newsletter";

//---------------------------------------------------------------------------------------
// The following sample shows how to add new content (or watermark) PDF pages
// using 'pdftron.PDF.Stamper' utility class. 
//
// Stamper can be used to 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.
//---------------------------------------------------------------------------------------

	PDFNet::Initialize($LicenseKey);
	PDFNet::GetSystemFontList();    // Wait for fonts to be loaded if they haven't already. This is done because PHP can run into errors when shutting down if font loading is still in progress.

	//--------------------------------------------------------------------------------
	// Example 1) Add text stamp to all pages, then remove text stamp from odd pages. 
	
	$doc = new PDFDoc($input_path.$input_filename.".pdf");
	$doc->InitSecurityHandler();
	$s = new Stamper(Stamper::e_relative_scale, 0.5, 0.5);		

	$s->SetAlignment(Stamper::e_horizontal_center, Stamper::e_vertical_center);
	$red = new ColorPt(1.0, 0.0, 0.0); // set text color to red
	$s->SetFontColor($red);
	$s->StampText($doc, "If you are reading this\nthis is an even page", new PageSet(1, $doc->GetPageCount()));
	//delete all text stamps in even pages
	Stamper::DeleteStamps($doc, new PageSet(1, $doc->GetPageCount(), PageSet::e_odd));

	$doc->Save($output_path.$input_filename.".ex1.pdf", SDFDoc::e_linearized);
	$doc->Close();

	//--------------------------------------------------------------------------------
	// Example 2) Add Image stamp to first 2 pages. 
	
	$doc = new PDFDoc($input_path.$input_filename.".pdf");
	$doc->InitSecurityHandler();

	$s = new Stamper(Stamper::e_relative_scale, 0.05, 0.05);
	$img = Image::Create($doc->GetSDFDoc(), $input_path."peppers.jpg");
	$s->SetSize(Stamper::e_relative_scale, 0.5, 0.5);
	//set position of the image to the center, left of PDF pages
	$s->SetAlignment(Stamper::e_horizontal_left, Stamper::e_vertical_center);
	$pt = new ColorPt(0.0, 0.0, 0.0, 0.0);
	$s->SetFontColor($pt);
	$s->SetRotation(180);
	$s->SetAsBackground(false);
	//only stamp first 2 pages
	$ps = new PageSet(1, 2);
	$s->StampImage($doc, $img, $ps);

	$doc->Save($output_path.$input_filename.".ex2.pdf", SDFDoc::e_linearized);
	$doc->Close();

	//--------------------------------------------------------------------------------
	// Example 3) Add Page stamp to all pages. 
	
	$doc = new PDFDoc($input_path.$input_filename.".pdf");
	$doc->InitSecurityHandler();

	$fish_doc = new PDFDoc($input_path."fish.pdf");
	$fish_doc->InitSecurityHandler();

	$s = new Stamper(Stamper::e_relative_scale, 0.5, 0.5);
	$src_page = $fish_doc->GetPage(1);		 
	$page_one_crop = $src_page->GetCropBox();
	// set size of the image to 10% of the original while keep the old aspect ratio
	$s->SetSize(Stamper::e_absolute_size, $page_one_crop->Width() * 0.1, -1);
	$s->SetOpacity(0.4);
	$s->SetRotation(-67);
	//put the image at the bottom right hand corner
	$s->SetAlignment(Stamper::e_horizontal_right, Stamper::e_vertical_bottom);
	$ps = new PageSet(1, $doc->GetPageCount());
	$s->StampPage($doc, $src_page, $ps);

	$doc->Save($output_path.$input_filename.".ex3.pdf", SDFDoc::e_linearized);
	$doc->Close();

	//--------------------------------------------------------------------------------
	// Example 4) Add Image stamp to first 20 odd pages.
	
	$doc = new PDFDoc($input_path.$input_filename.".pdf");
	$doc->InitSecurityHandler();

	$s = new Stamper(Stamper::e_absolute_size, 20.0, 20.0);
	$s->SetOpacity(1);
	$s->SetRotation(45);                
	$s->SetAsBackground(true);
	$s->SetPosition(30.0, 40.0);
	$img = Image::Create($doc->GetSDFDoc(), $input_path."peppers.jpg");
	$ps = new PageSet(1, 20, PageSet::e_odd);
	$s->StampImage($doc, $img, $ps);

	$doc->Save($output_path.$input_filename.".ex4.pdf", SDFDoc::e_linearized);
	$doc->Close();

	//--------------------------------------------------------------------------------
	// Example 5) Add text stamp to first 20 even pages
	
	$doc = new PDFDoc($input_path.$input_filename.".pdf");
	$doc->InitSecurityHandler();

	$s = new Stamper(Stamper::e_relative_scale, 0.05, 0.05);
	$s->SetPosition(0.0, 0.0);
	$s->SetOpacity(0.7);
	$s->SetRotation(90);
	$s->SetSize(Stamper::e_font_size, 80, -1);
	$s->SetTextAlignment(Stamper::e_align_center);
	$ps = new PageSet(1, 20, PageSet::e_even);
	$s->StampText($doc, "Goodbye\nMoon", $ps);

	$doc->Save($output_path.$input_filename.".ex5.pdf", SDFDoc::e_linearized);
	$doc->Close();

	//--------------------------------------------------------------------------------
	// Example 6) Add first page as stamp to all even pages
	
	$doc = new PDFDoc($input_path.$input_filename.".pdf");
	$doc->InitSecurityHandler();

	$fish_doc = new PDFDoc($input_path."fish.pdf");
	$fish_doc->InitSecurityHandler();

	$s = new Stamper(Stamper::e_relative_scale, 0.3, 0.3);
	$s->SetOpacity(1);                
	$s->SetRotation(270);
	$s->SetAsBackground(true);
	$s->SetPosition(0.5, 0.5, true);
	$s->SetAlignment(Stamper::e_horizontal_left, Stamper::e_vertical_bottom);
	$page_one = $fish_doc->GetPage(1);
	$ps = new PageSet(1, $doc->GetPageCount(), PageSet::e_even);
	$s->StampPage($doc, $page_one, $ps);

	$doc->Save($output_path.$input_filename.".ex6.pdf", SDFDoc::e_linearized);
	$doc->Close();

	//--------------------------------------------------------------------------------
	// Example 7) Add image stamp at top right corner in every pages
	
	$doc = new PDFDoc($input_path.$input_filename.".pdf");
	$doc->InitSecurityHandler();

	$s = new Stamper(Stamper::e_relative_scale, 0.1, 0.1);
	$s->SetOpacity(0.8);
	$s->SetRotation(135);
	$s->SetAsBackground(false);
	$s->ShowsOnPrint(false);
	$s->SetAlignment(Stamper::e_horizontal_left, Stamper::e_vertical_top);
	$s->SetPosition(10.0, 10.0);

	$img = Image::Create($doc->GetSDFDoc(), $input_path."peppers.jpg");
	$ps = new PageSet(1, $doc->GetPageCount(), PageSet::e_all);
	$s->StampImage($doc, $img, $ps);

	$doc->Save($output_path.$input_filename.".ex7.pdf", SDFDoc::e_linearized);
	$doc->Close();

	//--------------------------------------------------------------------------------
	// Example 8) Add Text stamp to first 2 pages, and image stamp to first page.
	//          Because text stamp is set as background, the image is top of the text
	//          stamp. Text stamp on the first page is not visible.
	
	$doc = new PDFDoc($input_path.$input_filename.".pdf");
	$doc->InitSecurityHandler();

	$s = new Stamper(Stamper::e_relative_scale, 0.07, -0.1);
	$s->SetAlignment(Stamper::e_horizontal_right, Stamper::e_vertical_bottom);
	$s->SetAlignment(Stamper::e_horizontal_center, Stamper::e_vertical_top);
	$s->SetFont(Font::Create($doc->GetSDFDoc(), Font::e_courier, true));
	$red = new ColorPt(1.0, 0.0, 0.0, 0.0);
	$s->SetFontColor($red); //set color to red
	$s->SetTextAlignment(Stamper::e_align_right);
	$s->SetAsBackground(true); //set text stamp as background
	$ps = new PageSet(1, 2);
	$s->StampText($doc, "This is a title!", $ps);

	$img = Image::Create($doc->GetSDFDoc(), $input_path."peppers.jpg");
	$s->SetAsBackground(false); // set image stamp as foreground
	$first_page_ps = new PageSet(1);
	$s->StampImage($doc, $img, $first_page_ps);

	$doc->Save($output_path.$input_filename.".ex8.pdf", SDFDoc::e_linearized);
	$doc->Close();
	PDFNet::Terminate();

?>
```

{% endcode %}
{% endtab %}

{% tab title="Python" %}
{% code lineNumbers="true" %}

```python
#---------------------------------------------------------------------------------------
# Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
# Consult LICENSE.txt regarding license information.
#---------------------------------------------------------------------------------------

import site
site.addsitedir("../../../PDFNetC/Lib")
import sys
from PDFNetPython import *

sys.path.append("../../LicenseKey/PYTHON")
from LicenseKey import *

#---------------------------------------------------------------------------------------
# The following sample shows how to add new content (or watermark) PDF pages
# using 'pdftron.PDF.Stamper' utility class. 
#
# Stamper can be used to 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.
#---------------------------------------------------------------------------------------

# Relative path to the folder containing the test files.
input_path = "../../TestFiles/"
output_path = "../../TestFiles/Output/"
input_filename = "newsletter"

def main():
    # Initialize PDFNet
    PDFNet.Initialize(LicenseKey)
    
    #--------------------------------------------------------------------------------
    # Example 1) Add text stamp to all pages, then remove text stamp from odd pages. 
    doc = PDFDoc(input_path + input_filename + ".pdf")
    doc.InitSecurityHandler()
    s = Stamper(Stamper.e_relative_scale, 0.5, 0.5)
    
    s.SetAlignment(Stamper.e_horizontal_center, Stamper.e_vertical_center)
    red = ColorPt(1, 0, 0) # set text color to red
    s.SetFontColor(red)
    s.StampText(doc, "If you are reading this\nthis is an even page", PageSet(1, doc.GetPageCount()))
    # delete all text stamps in odd pages
    Stamper.DeleteStamps(doc, PageSet(1, doc.GetPageCount(), PageSet.e_odd))
    
    doc.Save(output_path + input_filename + ".ex1.pdf", SDFDoc.e_linearized)
    doc.Close()

    #--------------------------------------------------------------------------------
    # Example 2) Add Image stamp to first 2 pages. 
    
    doc = PDFDoc(input_path + input_filename + ".pdf")
    doc.InitSecurityHandler()
    s = Stamper(Stamper.e_relative_scale, 0.05, 0.05)
    img = Image.Create(doc.GetSDFDoc(), input_path + "peppers.jpg")
    s.SetSize(Stamper.e_relative_scale, 0.5, 0.5)
    
    # set position of the image to the center, left of PDF pages
    s.SetAlignment(Stamper.e_horizontal_left, Stamper.e_vertical_center)
    pt = ColorPt(0, 0, 0, 0)
    s.SetFontColor(pt)
    s.SetRotation(180)
    s.SetAsBackground(False)
    # only stamp first 2 pages
    ps = PageSet(1, 2)
    s.StampImage(doc, img, ps)
    
    doc.Save(output_path + input_filename + ".ex2.pdf", SDFDoc.e_linearized)
    doc.Close()
    
    #--------------------------------------------------------------------------------
    # Example 3) Add Page stamp to all pages. 
    
    doc = PDFDoc(input_path + input_filename + ".pdf")
    doc.InitSecurityHandler()
    
    fish_doc = PDFDoc(input_path + "fish.pdf")
    fish_doc.InitSecurityHandler()
    s = Stamper(Stamper.e_relative_scale, 0.5, 0.5)
    src_page = fish_doc.GetPage(1)
    page_one_crop = src_page.GetCropBox()
    # set size of the image to 10% of the original while keep the old aspect ratio
    s.SetSize(Stamper.e_absolute_size, page_one_crop.Width() * 0.1, -1)
    s.SetOpacity(0.4)
    s.SetRotation(-67)
    # put the image at the bottom right hand corner
    s.SetAlignment(Stamper.e_horizontal_right, Stamper.e_vertical_bottom)
    ps = PageSet(1, doc.GetPageCount())
    s.StampPage(doc, src_page, ps)
    doc.Save(output_path + input_filename + ".ex3.pdf", SDFDoc.e_linearized)
    doc.Close()
    
    #--------------------------------------------------------------------------------
    # Example 4) Add Image stamp to first 20 odd pages.
    
    doc = PDFDoc(input_path + input_filename + ".pdf")
    doc.InitSecurityHandler()
    
    s = Stamper(Stamper.e_absolute_size, 20, 20)
    s.SetOpacity(1)
    s.SetRotation(45)
    s.SetAsBackground(True)
    s.SetPosition(30, 40)
    img = Image.Create(doc.GetSDFDoc(), input_path + "peppers.jpg")
    ps = PageSet(1, 20, PageSet.e_odd)
    s.StampImage(doc, img, ps)
    
    doc.Save(output_path + input_filename + ".ex4.pdf", SDFDoc.e_linearized)
    doc.Close()
    
    #--------------------------------------------------------------------------------
    # Example 5) Add text stamp to first 20 even pages
    
    doc = PDFDoc(input_path + input_filename + ".pdf")
    doc.InitSecurityHandler()
    s = Stamper(Stamper.e_relative_scale, 0.05, 0.05)
    s.SetPosition(0, 0)
    s.SetOpacity(0.7)
    s.SetRotation(90)
    s.SetSize(Stamper.e_font_size, 80, -1)
    s.SetTextAlignment(Stamper.e_align_center)
    ps = PageSet(1, 20, PageSet.e_even)
    s.StampText(doc, "Goodbye\nMoon", ps)
    
    doc.Save(output_path + input_filename + ".ex5.pdf", SDFDoc.e_linearized)
    doc.Close()
    
    #--------------------------------------------------------------------------------
    # Example 6) Add first page as stamp to all even pages
    
    doc = PDFDoc(input_path + input_filename + ".pdf")
    doc.InitSecurityHandler()
    
    fish_doc = PDFDoc(input_path + "fish.pdf");
    fish_doc.InitSecurityHandler()
    
    s = Stamper(Stamper.e_relative_scale, 0.3, 0.3)
    s.SetOpacity(1)
    s.SetRotation(270)
    s.SetAsBackground(True)
    s.SetPosition(0.5, 0.5, True)
    s.SetAlignment(Stamper.e_horizontal_left, Stamper.e_vertical_bottom)
    page_one = fish_doc.GetPage(1)
    ps = PageSet(1, doc.GetPageCount(), PageSet.e_even)
    s.StampPage(doc, page_one, ps)
    
    doc.Save(output_path + input_filename + ".ex6.pdf", SDFDoc.e_linearized)
    doc.Close()
    
    #--------------------------------------------------------------------------------
    # Example 7) Add image stamp at top left corner in every pages
    
    doc = PDFDoc(input_path + input_filename + ".pdf")
    doc.InitSecurityHandler()
    
    s = Stamper(Stamper.e_relative_scale, 0.1, 0.1)
    s.SetOpacity(0.8)
    s.SetRotation(135)
    s.SetAsBackground(False)
    s.ShowsOnPrint(False)
    s.SetAlignment(Stamper.e_horizontal_left, Stamper.e_vertical_top)
    s.SetPosition(10, 10)
    img = Image.Create(doc.GetSDFDoc(), input_path + "peppers.jpg")
    ps = PageSet(1, doc.GetPageCount(), PageSet.e_all)
    s.StampImage(doc, img, ps)
    doc.Save(output_path + input_filename + ".ex7.pdf", SDFDoc.e_linearized)
    doc.Close()
    
    #--------------------------------------------------------------------------------
    # Example 8) Add Text stamp to first 2 pages, and image stamp to first page.
    #          Because text stamp is set as background, the image is top of the text
    #          stamp. Text stamp on the first page is not visible.
    
    doc = PDFDoc(input_path + input_filename + ".pdf")
    doc.InitSecurityHandler()
    
    s = Stamper(Stamper.e_relative_scale, 0.07, -0.1)
    s.SetAlignment(Stamper.e_horizontal_right, Stamper.e_vertical_bottom)
    s.SetAlignment(Stamper.e_horizontal_center, Stamper.e_vertical_top)
    s.SetFont(Font.Create(doc.GetSDFDoc(), Font.e_courier, True))
    red = ColorPt(1, 0, 0) 
    s.SetFontColor(red) # set text color to red
    s.SetTextAlignment(Stamper.e_align_right)
    s.SetAsBackground(True) # set text stamp as background
    ps = PageSet(1, 2)
    s.StampText(doc, "This is a title!", ps)
    
    img = Image.Create(doc.GetSDFDoc(), input_path + "peppers.jpg")
    s.SetAsBackground(False)    # set image stamp as foreground
    first_page_ps = PageSet(1)
    s.StampImage(doc, img, first_page_ps)

    doc.Save(output_path + input_filename + ".ex8.pdf", SDFDoc.e_linearized)
    doc.Close()
    PDFNet.Terminate()

if __name__ == '__main__':
    main()
```

{% endcode %}
{% endtab %}

{% tab title="Ruby" %}
{% code lineNumbers="true" %}

```ruby
#---------------------------------------------------------------------------------------
# Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
# Consult LICENSE.txt regarding license information.
#---------------------------------------------------------------------------------------

require '../../../PDFNetC/Lib/PDFNetRuby'
include PDFNetRuby
require '../../LicenseKey/RUBY/LicenseKey'

$stdout.sync = true

#---------------------------------------------------------------------------------------
# The following sample shows how to add new content (or watermark) PDF pages
# using 'pdftron.PDF.Stamper' utility class. 
#
# Stamper can be used to 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.
#---------------------------------------------------------------------------------------

# Relative path to the folder containing the test files.
input_path = "../../TestFiles/"
output_path = "../../TestFiles/Output/"
input_filename = "newsletter"

	# Initialize PDFNet
	PDFNet.Initialize(PDFTronLicense.Key)
	
	#--------------------------------------------------------------------------------
	# Example 1) Add text stamp to all pages, then remove text stamp from odd pages. 
	
	doc = PDFDoc.new(input_path + input_filename + ".pdf")
	doc.InitSecurityHandler
	s = Stamper.new(Stamper::E_relative_scale, 0.5, 0.5)
	
	s.SetAlignment(Stamper::E_horizontal_center, Stamper::E_vertical_center)
	red = ColorPt.new(1, 0, 0) # set text color to red
	s.SetFontColor(red)
	s.StampText(doc, "If you are reading this\nthis is an even page", PageSet.new(1, doc.GetPageCount))
	# delete all text stamps in odd pages
	Stamper.DeleteStamps(doc, PageSet.new(1, doc.GetPageCount, PageSet::E_odd))
	
	doc.Save(output_path + input_filename + ".ex1.pdf", SDFDoc::E_linearized)
	doc.Close

	#--------------------------------------------------------------------------------
	# Example 2) Add Image stamp to first 2 pages. 
	
	doc = PDFDoc.new(input_path + input_filename + ".pdf")
	doc.InitSecurityHandler
	s = Stamper.new(Stamper::E_relative_scale, 0.05, 0.05)
	img = Image.Create(doc.GetSDFDoc, input_path + "peppers.jpg")
	s.SetSize(Stamper::E_relative_scale, 0.5, 0.5)
	
	# set position of the image to the center, left of PDF pages
	s.SetAlignment(Stamper::E_horizontal_left, Stamper::E_vertical_center)
	pt = ColorPt.new(0, 0, 0, 0)
	s.SetFontColor(pt)
	s.SetRotation(180)
	s.SetAsBackground(false)
	# only stamp first 2 pages
	ps = PageSet.new(1, 2)
	s.StampImage(doc, img, ps)
	
	doc.Save(output_path + input_filename + ".ex2.pdf", SDFDoc::E_linearized)
	doc.Close

	#--------------------------------------------------------------------------------
	# Example 3) Add Page stamp to all pages. 
	
	doc = PDFDoc.new(input_path + input_filename + ".pdf")
	doc.InitSecurityHandler
	
	fish_doc = PDFDoc.new(input_path + "fish.pdf")
	fish_doc.InitSecurityHandler
	s = Stamper.new(Stamper::E_relative_scale, 0.5, 0.5)
	src_page = fish_doc.GetPage(1)
	page_one_crop = src_page.GetCropBox
	# set size of the image to 10% of the original while keep the old aspect ratio
	s.SetSize(Stamper::E_absolute_size, page_one_crop.Width * 0.1, -1)
	s.SetOpacity(0.4)
	s.SetRotation(-67)
	# put the image at the bottom right hand corner
	s.SetAlignment(Stamper::E_horizontal_right, Stamper::E_vertical_bottom)
	ps = PageSet.new(1, doc.GetPageCount)
	s.StampPage(doc, src_page, ps)
	doc.Save(output_path + input_filename + ".ex3.pdf", SDFDoc::E_linearized)
	doc.Close

	#--------------------------------------------------------------------------------
	# Example 4) Add Image stamp to first 20 odd pages.
	
	doc = PDFDoc.new(input_path + input_filename + ".pdf")
	doc.InitSecurityHandler
	
	s = Stamper.new(Stamper::E_absolute_size, 20, 20)
	s.SetOpacity(1)
	s.SetRotation(45)
	s.SetAsBackground(true)
	s.SetPosition(30, 40)
	img = Image.Create(doc.GetSDFDoc, input_path + "peppers.jpg")
	ps = PageSet.new(1, 20, PageSet::E_odd)
	s.StampImage(doc, img, ps)
	
	doc.Save(output_path + input_filename + ".ex4.pdf", SDFDoc::E_linearized)
	doc.Close

	#--------------------------------------------------------------------------------
	# Example 5) Add text stamp to first 20 even pages
	
	doc = PDFDoc.new(input_path + input_filename + ".pdf")
	doc.InitSecurityHandler
	s = Stamper.new(Stamper::E_relative_scale, 0.05, 0.05)
	s.SetPosition(0, 0)
	s.SetOpacity(0.7)
	s.SetRotation(90)
	s.SetSize(Stamper::E_font_size, 80, -1)
	s.SetTextAlignment(Stamper::E_align_center)
	ps = PageSet.new(1, 20, PageSet::E_even)
	s.StampText(doc, "Goodbye\nMoon", ps)
	
	doc.Save(output_path + input_filename + ".ex5.pdf", SDFDoc::E_linearized)
	doc.Close

	#--------------------------------------------------------------------------------
	# Example 6) Add first page as stamp to all even pages
	
	doc = PDFDoc.new(input_path + input_filename + ".pdf")
	doc.InitSecurityHandler
	
	fish_doc = PDFDoc.new(input_path + "fish.pdf");
	fish_doc.InitSecurityHandler
	
	s = Stamper.new(Stamper::E_relative_scale, 0.3, 0.3)
	s.SetOpacity(1)
	s.SetRotation(270)
	s.SetAsBackground(true)
	s.SetPosition(0.5, 0.5, true)
	s.SetAlignment(Stamper::E_horizontal_left, Stamper::E_vertical_bottom)
	page_one = fish_doc.GetPage(1)
	ps = PageSet.new(1, doc.GetPageCount, PageSet::E_even)
	s.StampPage(doc, page_one, ps)
	
	doc.Save(output_path + input_filename + ".ex6.pdf", SDFDoc::E_linearized)
	doc.Close

	#--------------------------------------------------------------------------------
	# Example 7) Add image stamp at top left corner in every pages
	
	doc = PDFDoc.new(input_path + input_filename + ".pdf")
	doc.InitSecurityHandler
	
	s = Stamper.new(Stamper::E_relative_scale, 0.1, 0.1)
	s.SetOpacity(0.8)
	s.SetRotation(135)
	s.SetAsBackground(false)
	s.ShowsOnPrint(false)
	s.SetAlignment(Stamper::E_horizontal_left, Stamper::E_vertical_top)
	s.SetPosition(10, 10)
	img = Image.Create(doc.GetSDFDoc, input_path + "peppers.jpg")
	ps = PageSet.new(1, doc.GetPageCount, PageSet::E_all)
	s.StampImage(doc, img, ps)
	doc.Save(output_path + input_filename + ".ex7.pdf", SDFDoc::E_linearized)
	doc.Close

	#--------------------------------------------------------------------------------
	# Example 8) Add Text stamp to first 2 pages, and image stamp to first page.
	#          Because text stamp is set as background, the image is top of the text
	#          stamp. Text stamp on the first page is not visible.
	
	doc = PDFDoc.new(input_path + input_filename + ".pdf")
	doc.InitSecurityHandler
	
	s = Stamper.new(Stamper::E_relative_scale, 0.07, -0.1)
	s.SetAlignment(Stamper::E_horizontal_right, Stamper::E_vertical_bottom)
	s.SetAlignment(Stamper::E_horizontal_center, Stamper::E_vertical_top)
	s.SetFont(Font.Create(doc.GetSDFDoc, Font::E_courier, true))
	red = ColorPt.new(1, 0, 0) 
	s.SetFontColor(red) # set text color to red
	s.SetTextAlignment(Stamper::E_align_right)
	s.SetAsBackground(true) # set text stamp as background
	ps = PageSet.new(1, 2)
	s.StampText(doc, "This is a title!", ps)
	
	img = Image.Create(doc.GetSDFDoc, input_path + "peppers.jpg")
	s.SetAsBackground(false)    # set image stamp as foreground
	first_page_ps = PageSet.new(1)
	s.StampImage(doc, img, first_page_ps)

	doc.Save(output_path + input_filename + ".ex8.pdf", SDFDoc::E_linearized)
	doc.Close
	PDFNet.Terminate
```

{% endcode %}
{% endtab %}

{% tab title="VB" %}
{% code lineNumbers="true" %}

```vb
'
' Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
'
Imports System

Imports pdftron
Imports pdftron.Common
Imports pdftron.Filters
Imports pdftron.SDF
Imports pdftron.PDF

Module StamperTestVB
	Dim pdfNetLoader As PDFNetLoader
	Sub New()
		pdfNetLoader = pdftron.PDFNetLoader.Instance()
	End Sub

	' The following sample shows how to add new content (or watermark) PDF pages
	' using 'pdftron.PDF.Stamper' utility class. 
	'
	' Stamper can be used to 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.
	Sub Main()

		PDFNet.Initialize(PDFTronLicense.Key)

		Dim input_path As String = "../../../../TestFiles/"
		Dim output_path As String = "../../../../TestFiles/Output/"
		Dim input_filename As String = "newsletter"

		'--------------------------------------------------------------------------------
		' Example 1) Add text stamp to all pages, then remove text stamp from odd pages. 
		Try
			Using doc As PDFDoc = New PDFDoc(input_path + input_filename + ".pdf")
				doc.InitSecurityHandler()

				Using s As Stamper = New Stamper(Stamper.SizeType.e_relative_scale, 0.5, 0.5)
					s.SetAlignment(Stamper.HorizontalAlignment.e_horizontal_center, Stamper.VerticalAlignment.e_vertical_center)
					s.SetFontColor(New ColorPt(1, 0, 0)) ' set text color to red                
					s.StampText(doc, "If you are reading this" + ControlChars.Lf + "this is an even page", New PageSet(1, doc.GetPageCount()))
					'delete all text stamps in even pages
					Stamper.DeleteStamps(doc, New PageSet(1, doc.GetPageCount(), PageSet.Filter.e_odd))

					doc.Save(output_path + input_filename + ".ex1.pdf", SDFDoc.SaveOptions.e_linearized)
				End Using
			End Using
		Catch ex As PDFNetException
			Console.WriteLine(ex.Message)
		Catch ex As Exception
			MsgBox(ex.Message)
		End Try


		'--------------------------------------------------------------------------------
		' Example 2) Add Image stamp to first 2 pages. 
		Try
			Using doc As PDFDoc = New PDFDoc(input_path + input_filename + ".pdf")
				doc.InitSecurityHandler()

				Using s As Stamper = New Stamper(Stamper.SizeType.e_relative_scale, 0.05, 0.05)
					Dim img As Image = Image.Create(doc.GetSDFDoc(), input_path + "peppers.jpg")
					s.SetSize(Stamper.SizeType.e_relative_scale, 0.5, 0.5)
					'set position of the image to the center, left of PDF pages
					s.SetAlignment(Stamper.HorizontalAlignment.e_horizontal_left, Stamper.VerticalAlignment.e_vertical_center)
					s.SetFontColor(New ColorPt(0, 0, 0, 0))
					s.SetRotation(180)
					s.SetAsBackground(False)
					'only stamp first 2 pages
					s.StampImage(doc, img, New PageSet(1, 2))

					doc.Save(output_path + input_filename + ".ex2.pdf", SDFDoc.SaveOptions.e_linearized)
				End Using
			End Using
		Catch ex As PDFNetException
			Console.WriteLine(ex.Message)
		Catch ex As Exception
			MsgBox(ex.Message)
		End Try

		'--------------------------------------------------------------------------------
		' Example 3) Add Page stamp to all pages. 
		Try
			Using doc As PDFDoc = New PDFDoc(input_path + input_filename + ".pdf")
				doc.InitSecurityHandler()

				Using fish_doc As PDFDoc = New PDFDoc(input_path + "fish.pdf")
					fish_doc.InitSecurityHandler()

					Using s As Stamper = New Stamper(Stamper.SizeType.e_relative_scale, 0.5, 0.5)
						Dim src_page As Page = fish_doc.GetPage(1)
						Dim page_one_crop As Rect = src_page.GetCropBox()
						' set size of the image to 10% of the original while keep the old aspect ratio
						s.SetSize(Stamper.SizeType.e_absolute_size, page_one_crop.Width() * 0.1, -1)
						s.SetOpacity(0.4)
						s.SetRotation(-67)
						'put the image at the bottom right hand corner
						s.SetAlignment(Stamper.HorizontalAlignment.e_horizontal_right, Stamper.VerticalAlignment.e_vertical_bottom)
						s.StampPage(doc, src_page, New PageSet(1, doc.GetPageCount()))

						doc.Save(output_path + input_filename + ".ex3.pdf", SDFDoc.SaveOptions.e_linearized)
					End Using
				End Using
			End Using
		Catch ex As PDFNetException
			Console.WriteLine(ex.Message)
		Catch ex As Exception
			MsgBox(ex.Message)
		End Try

		'--------------------------------------------------------------------------------
		' Example 4) Add Image stamp to first 20 odd pages. 
		Try
			Using doc As PDFDoc = New PDFDoc(input_path + input_filename + ".pdf")
				doc.InitSecurityHandler()

				Using s As Stamper = New Stamper(Stamper.SizeType.e_absolute_size, 20, 20)
					s.SetOpacity(1)
					s.SetRotation(45)
					s.SetAsBackground(True)
					s.SetPosition(30, 40)
					Dim img As Image = Image.Create(doc.GetSDFDoc(), input_path + "peppers.jpg")
					s.StampImage(doc, img, New PageSet(1, 20, PageSet.Filter.e_odd))

					doc.Save(output_path + input_filename + ".ex4.pdf", SDFDoc.SaveOptions.e_linearized)
				End Using
			End Using
		Catch ex As PDFNetException
			Console.WriteLine(ex.Message)
		Catch ex As Exception
			MsgBox(ex.Message)
		End Try

		'--------------------------------------------------------------------------------
		' Example 5) Add text stamp to first 20 even pages
		Try
			Using doc As PDFDoc = New PDFDoc(input_path + input_filename + ".pdf")
				doc.InitSecurityHandler()

				Using s As Stamper = New Stamper(Stamper.SizeType.e_relative_scale, 0.05, 0.05)
					s.SetPosition(0, 0)
					s.SetOpacity(0.7)
					s.SetRotation(90)
					s.SetSize(Stamper.SizeType.e_font_size, 80, -1)
					s.SetTextAlignment(Stamper.TextAlignment.e_align_center)
					s.StampText(doc, "Goodbye" + ControlChars.Lf + "Moon", New PageSet(1, 20, PageSet.Filter.e_even))

					doc.Save(output_path + input_filename + ".ex5.pdf", SDFDoc.SaveOptions.e_linearized)
				End Using
			End Using
		Catch ex As PDFNetException
			Console.WriteLine(ex.Message)
		Catch ex As Exception
			MsgBox(ex.Message)
		End Try


		'--------------------------------------------------------------------------------
		' Example 6) Add first page as stamp to all even pages
		Try
			Using doc As PDFDoc = New PDFDoc(input_path + input_filename + ".pdf")
				doc.InitSecurityHandler()

				Using fish_doc As PDFDoc = New PDFDoc(input_path + "fish.pdf")
					fish_doc.InitSecurityHandler()

					Using s As Stamper = New Stamper(Stamper.SizeType.e_relative_scale, 0.3, 0.3)
						s.SetOpacity(1)
						s.SetRotation(270)
						s.SetAsBackground(True)
						s.SetPosition(0.5, 0.5, True)
						s.SetAlignment(Stamper.HorizontalAlignment.e_horizontal_left, Stamper.VerticalAlignment.e_vertical_bottom)
						Dim page_one As Page = fish_doc.GetPage(1)
						s.StampPage(doc, page_one, New PageSet(1, doc.GetPageCount(), PageSet.Filter.e_even))

						doc.Save(output_path + input_filename + ".ex6.pdf", SDFDoc.SaveOptions.e_linearized)
					End Using
				End Using
			End Using
		Catch ex As PDFNetException
			Console.WriteLine(ex.Message)
		Catch ex As Exception
			MsgBox(ex.Message)
		End Try

		'--------------------------------------------------------------------------------
		' Example 7) Add image stamp at top right corner in every pages
		Try
			Using doc As PDFDoc = New PDFDoc(input_path + input_filename + ".pdf")
				doc.InitSecurityHandler()

				Using s As Stamper = New Stamper(Stamper.SizeType.e_relative_scale, 0.1, 0.1)
					s.SetOpacity(0.8)
					s.SetRotation(135)
					s.SetAsBackground(False)
					s.ShowsOnPrint(False)
					s.SetAlignment(Stamper.HorizontalAlignment.e_horizontal_left, Stamper.VerticalAlignment.e_vertical_top)
					s.SetPosition(10, 10)

					Dim img As Image = Image.Create(doc.GetSDFDoc(), input_path + "peppers.jpg")
					s.StampImage(doc, img, New PageSet(1, doc.GetPageCount(), PageSet.Filter.e_all))

					doc.Save(output_path + input_filename + ".ex7.pdf", SDFDoc.SaveOptions.e_linearized)
				End Using
			End Using
		Catch ex As PDFNetException
			Console.WriteLine(ex.Message)
		Catch ex As Exception
			MsgBox(ex.Message)
		End Try

		'--------------------------------------------------------------------------------
		' Example 8) Add Text stamp to first 2 pages, and image stamp to first page.
		'          Because text stamp is set as background, the image is top of the text
		'          stamp. Text stamp on the first page is not visible.
		Try
			Using doc As PDFDoc = New PDFDoc(input_path + input_filename + ".pdf")
				doc.InitSecurityHandler()

				Using s As Stamper = New Stamper(Stamper.SizeType.e_relative_scale, 0.07, -0.1)
					s.SetAlignment(Stamper.HorizontalAlignment.e_horizontal_right, Stamper.VerticalAlignment.e_vertical_bottom)
					s.SetAlignment(Stamper.HorizontalAlignment.e_horizontal_center, Stamper.VerticalAlignment.e_vertical_top)
					s.SetFont(Font.Create(doc, Font.StandardType1Font.e_courier, True))
					s.SetFontColor(New ColorPt(1, 0, 0, 0))	'set color to red
					s.SetTextAlignment(Stamper.TextAlignment.e_align_right)
					s.SetAsBackground(True)	'set text stamp as background
					s.StampText(doc, "This is a title!", New PageSet(1, 2))

					Dim img As Image = Image.Create(doc.GetSDFDoc(), input_path + "peppers.jpg")
					s.SetAsBackground(False) ' set image stamp as foreground
					s.StampImage(doc, img, New PageSet(1))

					doc.Save(output_path + input_filename + ".ex8.pdf", SDFDoc.SaveOptions.e_linearized)
				End Using
			End Using
		Catch ex As PDFNetException
			Console.WriteLine(ex.Message)
		Catch ex As Exception
			MsgBox(ex.Message)
		End Try
		PDFNet.Terminate()
	End Sub
End Module
```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/core/get-started/samples/stampertest.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
