Add a stamp annotation to a PDF on Server/Desktop

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

Apryse SDK benefits include:

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

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

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

1$doc = new PDFDoc($filename);
2$s = new Stamper(Stamper::e_relative_scale, 0.05, 0.05);
3
4// Specifies if the stamp is to be stamped as an annotation.
5// note that stamps created with this setting do not work with SetAsBackground, HasStamps, and DeleteStamps, if annotation is true.
6//$s->SetAsAnnotation(true);
7
8$s->SetAlignment(Stamper::e_horizontal_right, Stamper::e_vertical_bottom);
9$s->SetAlignment(Stamper::e_horizontal_center, Stamper::e_vertical_top);
10$s->SetFont(Font::Create($doc->GetSDFDoc(), Font::e_courier, true));
11$red = new ColorPt(1.0, 0.0, 0.0, 0.0);
12$s->SetFontColor($red); //set color to red
13$s->SetTextAlignment(Stamper::e_align_right);
14$s->SetAsBackground(true); //set text stamp as background
15$ps = new PageSet(1, 2);
16$s->StampText($doc, "This is a title!", $ps);
17
18$img = Image::Create($doc->GetSDFDoc(), $imagename);
19$s->SetAsBackground(false); // set image stamp as foreground
20$first_page_ps = new PageSet(1);
21$s->StampImage($doc, $img, $first_page_ps);
22
23$src_doc = new PDFDoc($src_filename);
24$src_page = $src_doc->GetPage(1);
25$s->StampPage($doc, $src_page, $ps);

Stamp a PDF File - Full Sample
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 .

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales