Some test text!

Search
Hamburger Icon

Cpp / Guides / Stamp content

Adding a stamp to PDFs in C++

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.

PDFDoc doc(filename);
Stamper s(Stamper::e_relative_scale, .05, .05);

// 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);

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, imagename);
s.SetAsBackground(false); // set image stamp as foreground
PageSet first_page_ps(1);
s.StampImage(doc, img, first_page_ps);

PDFDoc src_doc(src_filename);
Page src_page = src_doc.GetPage(1);
s.StampPage(doc, src_page, first_page_ps);

Stamp a PDF File
Full code sample which shows how to stamp PDF pages with text, images, or with other PDF pages and how to add new content (or watermark).

About Stamper

Stamper can be used for PDF pages with text, images, or with other PDF content in only a few lines of code. Although Stamper is very simple to use compared to ElementBuilder/ElementWriter it is not as powerful or flexible. In case you need full control over PDF creation use ElementBuilder/ElementWriter to add new content to existing PDF pages as shown in the ElementBuilder sample project .

Get the answers you need: Chat with us