PDF SDK Documentation

Comprehensive Guide for Developers: Features, Integration, and API Reference

Loading...
Searching...
No Matches
stamper.h
1// Copyright (c) 2009-2026 Avanquest Software. All rights reserved.
2
3#ifndef PDFSDK_CXX_STAMPER_H_INCLUDED_
4#define PDFSDK_CXX_STAMPER_H_INCLUDED_
5
6#include <filesystem>
7#include <string>
8#include <vector>
9
10#include <pdfsdk/cxx/document.h>
11#include <pdfsdk/cxx/graphics.h>
12#include <pdfsdk/cxx/wrapper_base.h>
13#include <pdfsdk/stamper.h>
14
15namespace PDF {
16
27class Stamper : public detail::RefCountedHandle<PDFStamper> {
28public:
35 static Stamper Create(PDFStampSizeMode sizeMode, float a, float b);
36
43 void SetSize(PDFStampSizeMode sizeMode, float a, float b);
44
52 void SetPosition(float horizontalDistance, float verticalDistance, bool usePercentage = false);
53
60 void SetAlignment(PDFStampHAlign hAlign, PDFStampVAlign vAlign);
61
66 void SetRotation(float degrees);
67
72 void SetOpacity(float opacity);
73
80 void SetAsBackground(bool background);
81
90 void SetAsAnnotation(bool annotation);
91
96 void ShowsOnScreen(bool onScreen);
97
104 void ShowsOnPrint(bool onPrint);
105
113 void ShowsInLayersPanel(bool inLayersPanel);
114
122 void SetName(const std::wstring& name);
123
130 void SetFont(const PDFontInfo& fontInfo);
131
137 void SetFontColor(PDColorValue color);
138
145 void SetTextOutline(PDColorValue strokeColor, float strokeWidth);
146
151 void SetTextAlignment(PDFStampTextAlign textAlign);
152
159 void StampText(const Document& destDoc, const std::wstring& text, const std::vector<size_t>& destPages = {});
160
167 void StampImage(const Document& destDoc, const Graphics::Bitmap& bitmap, const std::vector<size_t>& destPages = {});
168
175 void StampImageFromFile(const Document& destDoc, const std::filesystem::path& imagePath, const std::vector<size_t>& destPages = {});
176
184 void StampPage(const Document& destDoc, const Document& srcDoc, size_t srcPageIndex, const std::vector<size_t>& destPages = {});
185
193 static bool HasStamps(const Document& doc, const std::vector<size_t>& pages = {});
194
201 static void DeleteStamps(const Document& doc, const std::vector<size_t>& pages = {});
202
203 PDF_CXX_CORE_WRAPPER_DEFINE_MEMBERS_(Stamper, PDFStamper)
204};
205
206namespace detail {
207
208inline PDPageRange MakePageRange(const std::vector<size_t>& pages) {
209 return {pages.data(), pages.size()};
210}
211
212} // namespace detail
213
214inline Stamper Stamper::Create(PDFStampSizeMode sizeMode, float a, float b) {
215 Stamper stamper;
216 PDF_CHECK_SUCCESS_X(PDFStamperCreate(sizeMode, a, b, &stamper));
217 return stamper;
218}
219
220inline void Stamper::SetSize(PDFStampSizeMode sizeMode, float a, float b) {
221 PDF_CHECK_SUCCESS_X(PDFStamperSetSize(m_handle, sizeMode, a, b));
222}
223
224inline void Stamper::SetPosition(float horizontalDistance, float verticalDistance, bool usePercentage) {
225 PDF_CHECK_SUCCESS_X(PDFStamperSetPosition(m_handle, horizontalDistance, verticalDistance, usePercentage));
226}
227
229 PDF_CHECK_SUCCESS_X(PDFStamperSetAlignment(m_handle, hAlign, vAlign));
230}
231
232inline void Stamper::SetRotation(float degrees) {
233 PDF_CHECK_SUCCESS_X(PDFStamperSetRotation(m_handle, degrees));
234}
235
236inline void Stamper::SetOpacity(float opacity) {
237 PDF_CHECK_SUCCESS_X(PDFStamperSetOpacity(m_handle, opacity));
238}
239
240inline void Stamper::SetAsBackground(bool background) {
241 PDF_CHECK_SUCCESS_X(PDFStamperSetAsBackground(m_handle, background));
242}
243
244inline void Stamper::SetAsAnnotation(bool annotation) {
245 PDF_CHECK_SUCCESS_X(PDFStamperSetAsAnnotation(m_handle, annotation));
246}
247
248inline void Stamper::ShowsOnScreen(bool onScreen) {
249 PDF_CHECK_SUCCESS_X(PDFStamperShowsOnScreen(m_handle, onScreen));
250}
251
252inline void Stamper::ShowsOnPrint(bool onPrint) {
253 PDF_CHECK_SUCCESS_X(PDFStamperShowsOnPrint(m_handle, onPrint));
254}
255
256inline void Stamper::ShowsInLayersPanel(bool inLayersPanel) {
257 PDF_CHECK_SUCCESS_X(PDFStamperShowsInLayersPanel(m_handle, inLayersPanel));
258}
259
260inline void Stamper::SetName(const std::wstring& name) {
261 PDF_CHECK_SUCCESS_X(PDFStamperSetName(m_handle, name.c_str()));
262}
263
264inline void Stamper::SetFont(const PDFontInfo& fontInfo) {
265 PDF_CHECK_SUCCESS_X(PDFStamperSetFont(m_handle, &fontInfo));
266}
267
268inline void Stamper::SetFontColor(PDColorValue color) {
269 PDF_CHECK_SUCCESS_X(PDFStamperSetFontColor(m_handle, color));
270}
271
272inline void Stamper::SetTextOutline(PDColorValue strokeColor, float strokeWidth) {
273 PDF_CHECK_SUCCESS_X(PDFStamperSetTextOutline(m_handle, strokeColor, strokeWidth));
274}
275
277 PDF_CHECK_SUCCESS_X(PDFStamperSetTextAlignment(m_handle, textAlign));
278}
279
280inline void Stamper::StampText(const Document& destDoc, const std::wstring& text, const std::vector<size_t>& destPages) {
281 PDPageRange range = detail::MakePageRange(destPages);
282 const PDPageRange* rangePtr = destPages.empty() ? nullptr : &range;
283 PDF_CHECK_SUCCESS_X(PDFStamperStampText(m_handle, destDoc.get(), text.c_str(), rangePtr));
284}
285
286inline void Stamper::StampImage(const Document& destDoc, const Graphics::Bitmap& bitmap, const std::vector<size_t>& destPages) {
287 PDPageRange range = detail::MakePageRange(destPages);
288 const PDPageRange* rangePtr = destPages.empty() ? nullptr : &range;
289 PDF_CHECK_SUCCESS_X(PDFStamperStampImage(m_handle, destDoc.get(), bitmap.get(), rangePtr));
290}
291
292inline void Stamper::StampImageFromFile(const Document& destDoc, const std::filesystem::path& imagePath, const std::vector<size_t>& destPages) {
293 PDPageRange range = detail::MakePageRange(destPages);
294 const PDPageRange* rangePtr = destPages.empty() ? nullptr : &range;
295 PDF_CHECK_SUCCESS_X(PDFStamperStampImageFromFile(m_handle, destDoc.get(), imagePath.wstring().c_str(), rangePtr));
296}
297
298inline void Stamper::StampPage(const Document& destDoc, const Document& srcDoc, size_t srcPageIndex, const std::vector<size_t>& destPages) {
299 PDPageRange range = detail::MakePageRange(destPages);
300 const PDPageRange* rangePtr = destPages.empty() ? nullptr : &range;
301 PDF_CHECK_SUCCESS_X(PDFStamperStampPage(m_handle, destDoc.get(), srcDoc.get(), srcPageIndex, rangePtr));
302}
303
304inline bool Stamper::HasStamps(const Document& doc, const std::vector<size_t>& pages) {
305 PDPageRange range = detail::MakePageRange(pages);
306 const PDPageRange* rangePtr = pages.empty() ? nullptr : &range;
307 bool hasStamps = false;
308 PDF_CHECK_SUCCESS_X(PDFStamperHasStamps(doc.get(), rangePtr, &hasStamps));
309 return hasStamps;
310}
311
312inline void Stamper::DeleteStamps(const Document& doc, const std::vector<size_t>& pages) {
313 PDPageRange range = detail::MakePageRange(pages);
314 const PDPageRange* rangePtr = pages.empty() ? nullptr : &range;
315 PDF_CHECK_SUCCESS_X(PDFStamperDeleteStamps(doc.get(), rangePtr));
316}
317
318} // namespace PDF
319
320#endif // PDFSDK_CXX_STAMPER_H_INCLUDED_
Represents a PDF document.
Definition document.h:27
Represents a bitmap.
Definition graphics.h:69
Stamps PDF pages with text, raster images or another PDF page.
Definition stamper.h:27
static Stamper Create(PDFStampSizeMode sizeMode, float a, float b)
Creates a new Stamper with an initial size.
Definition stamper.h:214
void SetAlignment(PDFStampHAlign hAlign, PDFStampVAlign vAlign)
Sets the anchor that the position offset is measured from. Default is centered (kPDFStampHAlignCenter...
Definition stamper.h:228
void SetOpacity(float opacity)
Sets the opacity of the stamp.
Definition stamper.h:236
void StampImage(const Document &destDoc, const Graphics::Bitmap &bitmap, const std::vector< size_t > &destPages={})
Stamps a raster image from an in-memory bitmap onto the given pages.
Definition stamper.h:286
void SetSize(PDFStampSizeMode sizeMode, float a, float b)
Sets how the stamp is sized. Overrides the value passed to Create.
Definition stamper.h:220
void SetPosition(float horizontalDistance, float verticalDistance, bool usePercentage=false)
Sets the offset of the stamp from the alignment anchor. Default is no offset (0, 0).
Definition stamper.h:224
void SetName(const std::wstring &name)
Sets the stamp name. Default is "Stamp".
Definition stamper.h:260
void SetAsBackground(bool background)
Specifies whether the stamp is placed behind the page content (background) or on top....
Definition stamper.h:240
void ShowsOnPrint(bool onPrint)
Specifies whether the stamp is visible when the document is printed. Default is true.
Definition stamper.h:252
void SetTextAlignment(PDFStampTextAlign textAlign)
Sets the alignment of multi-line text within a text stamp. Default is kPDFStampTextAlignLeft.
Definition stamper.h:276
static bool HasStamps(const Document &doc, const std::vector< size_t > &pages={})
Reports whether any of the given pages contains at least one stamp.
Definition stamper.h:304
void StampText(const Document &destDoc, const std::wstring &text, const std::vector< size_t > &destPages={})
Stamps text onto the given pages using the configured font, color and text alignment.
Definition stamper.h:280
void SetRotation(float degrees)
Sets the rotation of the stamp, in degrees, counter-clockwise. Default is 0 (no rotation).
Definition stamper.h:232
void SetFont(const PDFontInfo &fontInfo)
Sets the font used for text stamps.
Definition stamper.h:264
static void DeleteStamps(const Document &doc, const std::vector< size_t > &pages={})
Deletes all stamps from the given pages.
Definition stamper.h:312
void StampPage(const Document &destDoc, const Document &srcDoc, size_t srcPageIndex, const std::vector< size_t > &destPages={})
Stamps a single page from a source PDF document (as vector art) onto the given pages.
Definition stamper.h:298
void ShowsOnScreen(bool onScreen)
Specifies whether the stamp is visible on screen. Default is true.
Definition stamper.h:248
void SetTextOutline(PDColorValue strokeColor, float strokeWidth)
Gives text stamps an outline (stroke), in addition to or instead of the fill.
Definition stamper.h:272
void SetFontColor(PDColorValue color)
Sets the color used for text stamps.
Definition stamper.h:268
void StampImageFromFile(const Document &destDoc, const std::filesystem::path &imagePath, const std::vector< size_t > &destPages={})
Stamps a raster image loaded from a file onto the given pages.
Definition stamper.h:292
void SetAsAnnotation(bool annotation)
Specifies whether the stamp is added as a Stamp annotation instead of page content....
Definition stamper.h:244
void ShowsInLayersPanel(bool inLayersPanel)
Specifies whether the stamp's optional-content layer is registered in the document's layer order (/Or...
Definition stamper.h:256
The PDF Stamper API.
PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperStampImageFromFile(PDFStamper stamper, PDDoc destDoc, const wchar_t *imagePath, const PDPageRange *destPages)
Stamps a raster image loaded from a file onto the given pages.
PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperHasStamps(PDDoc doc, const PDPageRange *pages, bool *pHasStamps)
Reports whether any of the given pages contains at least one stamp.
PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperStampText(PDFStamper stamper, PDDoc destDoc, const wchar_t *text, const PDPageRange *destPages)
Stamps text onto the given pages using the configured font, color and text alignment.
PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperSetOpacity(PDFStamper stamper, float opacity)
Sets the opacity of the stamp.
PDFStampVAlign
Vertical alignment of the stamp relative to the crop box.
Definition stamper.h:70
PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperSetTextAlignment(PDFStamper stamper, PDFStampTextAlign textAlign)
Sets the alignment of multi-line text within a text stamp. Default is kPDFStampTextAlignLeft.
PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperShowsOnPrint(PDFStamper stamper, bool onPrint)
Specifies whether the stamp is visible when the document is printed. Default is true.
struct PDFStamperRec_ * PDFStamper
The opaque handle to the PDFStamper object.
Definition stamper.h:89
PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperSetAsAnnotation(PDFStamper stamper, bool annotation)
Specifies whether the stamp is added as a Stamp annotation instead of page content....
PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperSetFont(PDFStamper stamper, const PDFontInfo *fontInfo)
Sets the font used for text stamps.
PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperSetAlignment(PDFStamper stamper, PDFStampHAlign hAlign, PDFStampVAlign vAlign)
Sets the anchor that the position offset is measured from. Default is centered (kPDFStampHAlignCenter...
PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperSetSize(PDFStamper stamper, PDFStampSizeMode sizeMode, float a, float b)
Sets how the stamp is sized. Overrides the value passed to PDFStamperCreate.
PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperSetPosition(PDFStamper stamper, float horizontalDistance, float verticalDistance, bool usePercentage)
Sets the offset of the stamp from the alignment anchor. Default is no offset (0, 0).
PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperSetTextOutline(PDFStamper stamper, PDColorValue strokeColor, float strokeWidth)
Gives text stamps an outline (stroke), in addition to or instead of the fill.
PDFStampTextAlign
Alignment of multi-line text within a text stamp.
Definition stamper.h:79
PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperStampImage(PDFStamper stamper, PDDoc destDoc, GXBitmap bitmap, const PDPageRange *destPages)
Stamps a raster image from an in-memory bitmap onto the given pages.
PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperShowsInLayersPanel(PDFStamper stamper, bool inLayersPanel)
Specifies whether the stamp's optional-content layer is registered in the document's layer order (/Or...
PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperCreate(PDFStampSizeMode sizeMode, float a, float b, PDFStamper *pStamper)
Creates a new PDFStamper object with an initial size.
PDFStampSizeMode
Specifies how a stamp is sized.
Definition stamper.h:38
PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperSetName(PDFStamper stamper, const wchar_t *name)
Sets the stamp name. Default is "Stamp".
PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperSetFontColor(PDFStamper stamper, PDColorValue color)
Sets the color used for text stamps.
PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperSetAsBackground(PDFStamper stamper, bool background)
Specifies whether the stamp is placed behind the page content (background) or on top (foreground)....
PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperSetRotation(PDFStamper stamper, float degrees)
Sets the rotation of the stamp, in degrees, counter-clockwise. Default is 0 (no rotation).
PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperStampPage(PDFStamper stamper, PDDoc destDoc, PDDoc srcDoc, size_t srcPageIndex, const PDPageRange *destPages)
Stamps a single page from a source PDF document (as vector art) onto the given pages.
PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperDeleteStamps(PDDoc doc, const PDPageRange *pages)
Deletes all stamps from the given pages.
PDFStampHAlign
Horizontal alignment of the stamp relative to the crop box.
Definition stamper.h:61
PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperShowsOnScreen(PDFStamper stamper, bool onScreen)
Specifies whether the stamp is visible on screen. Default is true.
Specifies the font information.
Definition fonts.h:36
Specifies a structure to define a set of pages.
Definition document.h:44