PDF SDK Documentation

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

Loading...
Searching...
No Matches

Stamps PDF pages with text, raster images or another PDF page. More...

#include <pdfsdk/cxx/stamper.h>

Inheritance diagram for PDF::Stamper:

Public Member Functions

void SetSize (PDFStampSizeMode sizeMode, float a, float b)
 Sets how the stamp is sized. Overrides the value passed to Create.
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).
void SetAlignment (PDFStampHAlign hAlign, PDFStampVAlign vAlign)
 Sets the anchor that the position offset is measured from. Default is centered (kPDFStampHAlignCenter, kPDFStampVAlignCenter).
void SetRotation (float degrees)
 Sets the rotation of the stamp, in degrees, counter-clockwise. Default is 0 (no rotation).
void SetOpacity (float opacity)
 Sets the opacity of the stamp.
void SetAsBackground (bool background)
 Specifies whether the stamp is placed behind the page content (background) or on top. Default is on top (foreground).
void SetAsAnnotation (bool annotation)
 Specifies whether the stamp is added as a Stamp annotation instead of page content. Default is page content.
void ShowsOnScreen (bool onScreen)
 Specifies whether the stamp is visible on screen. Default is true.
void ShowsOnPrint (bool onPrint)
 Specifies whether the stamp is visible when the document is printed. Default is true.
void ShowsInLayersPanel (bool inLayersPanel)
 Specifies whether the stamp's optional-content layer is registered in the document's layer order (/Order) so it appears in a viewer's layers panel. Default is false.
void SetName (const std::wstring &name)
 Sets the stamp name. Default is "Stamp".
void SetFont (const PDFontInfo &fontInfo)
 Sets the font used for text stamps.
void SetFontColor (PDColorValue color)
 Sets the color used for text stamps.
void SetTextOutline (PDColorValue strokeColor, float strokeWidth)
 Gives text stamps an outline (stroke), in addition to or instead of the fill.
void SetTextAlignment (PDFStampTextAlign textAlign)
 Sets the alignment of multi-line text within a text stamp. Default is kPDFStampTextAlignLeft.
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.
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.
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.
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.

Static Public Member Functions

static Stamper Create (PDFStampSizeMode sizeMode, float a, float b)
 Creates a new Stamper with an initial size.
static bool HasStamps (const Document &doc, const std::vector< size_t > &pages={})
 Reports whether any of the given pages contains at least one stamp.
static void DeleteStamps (const Document &doc, const std::vector< size_t > &pages={})
 Deletes all stamps from the given pages.

Detailed Description

Stamps PDF pages with text, raster images or another PDF page.

A Stamper is a configuration object: set the size, position, alignment, rotation and opacity once, then call one of the Stamp* methods repeatedly to apply the stamp to a set of pages. Stamped content is wrapped in a standard PDF marked-content artifact so it can be located and removed later via HasStamps / DeleteStamps.

For full control over PDF content creation use the Element / Content API instead.

Member Function Documentation

◆ Create()

Stamper PDF::Stamper::Create ( PDFStampSizeMode sizeMode,
float a,
float b )
inlinestatic

Creates a new Stamper with an initial size.

Parameters
[in]sizeModeHow the stamp is sized.
See also
PDFStampSizeMode
Parameters
[in]aThe horizontal size component. Meaning depends on sizeMode.
[in]bThe vertical size component. Meaning depends on sizeMode.

◆ DeleteStamps()

void PDF::Stamper::DeleteStamps ( const Document & doc,
const std::vector< size_t > & pages = {} )
inlinestatic

Deletes all stamps from the given pages.

Parameters
[in]docThe document to delete stamps from.
[in]pagesThe zero-based page indices to delete stamps from. Empty means all pages.
Note
Only content stamps are removed; annotation stamps (SetAsAnnotation) are not.

◆ HasStamps()

bool PDF::Stamper::HasStamps ( const Document & doc,
const std::vector< size_t > & pages = {} )
inlinestatic

Reports whether any of the given pages contains at least one stamp.

Parameters
[in]docThe document to check.
[in]pagesThe zero-based page indices to check. Empty means all pages.
Returns
True if at least one stamp is found.
Note
Only content stamps are detected; annotation stamps (SetAsAnnotation) are not.

◆ SetAlignment()

void PDF::Stamper::SetAlignment ( PDFStampHAlign hAlign,
PDFStampVAlign vAlign )
inline

Sets the anchor that the position offset is measured from. Default is centered (kPDFStampHAlignCenter, kPDFStampVAlignCenter).

Parameters
[in]hAlignHorizontal anchor.
See also
PDFStampHAlign
Parameters
[in]vAlignVertical anchor.
See also
PDFStampVAlign

◆ SetAsAnnotation()

void PDF::Stamper::SetAsAnnotation ( bool annotation)
inline

Specifies whether the stamp is added as a Stamp annotation instead of page content. Default is page content.

Annotation stamps are not affected by SetAsBackground and are not found or removed by HasStamps / DeleteStamps.

Parameters
[in]annotationIf true, the stamp is added as a Stamp annotation; otherwise into the page content.

◆ SetAsBackground()

void PDF::Stamper::SetAsBackground ( bool background)
inline

Specifies whether the stamp is placed behind the page content (background) or on top. Default is on top (foreground).

Parameters
[in]backgroundIf true, the stamp is inserted as a background layer; otherwise on top.
Note
Ignored for annotation stamps (SetAsAnnotation).

◆ SetFont()

void PDF::Stamper::SetFont ( const PDFontInfo & fontInfo)
inline

Sets the font used for text stamps.

Parameters
[in]fontInfoThe font description (family, format, style).
See also
PDFontInfo
Note
When left unset, text stamps default to kPDAtom_Helvetica with kPDFontStyleRegular in black.
The font size is controlled by SetSize with kPDFStampSizeFontSize.

◆ SetFontColor()

void PDF::Stamper::SetFontColor ( PDColorValue color)
inline

Sets the color used for text stamps.

Parameters
[in]colorThe font color.
See also
PDColorValue
Note
When left unset, text stamps default to black.

◆ SetName()

void PDF::Stamper::SetName ( const std::wstring & name)
inline

Sets the stamp name. Default is "Stamp".

Used as the annotation title for annotation stamps, and as the optional content layer name for content stamps whose screen/print visibility is restricted.

Parameters
[in]nameThe name.

◆ SetOpacity()

void PDF::Stamper::SetOpacity ( float opacity)
inline

Sets the opacity of the stamp.

Parameters
[in]opacityThe opacity in the range [0, 1], where 1 is fully opaque. Default is 1.

◆ SetPosition()

void PDF::Stamper::SetPosition ( float horizontalDistance,
float verticalDistance,
bool usePercentage = false )
inline

Sets the offset of the stamp from the alignment anchor. Default is no offset (0, 0).

Parameters
[in]horizontalDistanceHorizontal offset from the left/right/center anchor.
[in]verticalDistanceVertical offset from the top/bottom/center anchor.
[in]usePercentageIf true, the distances are fractions of the crop box width/height; if false, they are measured in points.

◆ SetRotation()

void PDF::Stamper::SetRotation ( float degrees)
inline

Sets the rotation of the stamp, in degrees, counter-clockwise. Default is 0 (no rotation).

Parameters
[in]degreesThe rotation in degrees.

◆ SetSize()

void PDF::Stamper::SetSize ( PDFStampSizeMode sizeMode,
float a,
float b )
inline

Sets how the stamp is sized. Overrides the value passed to Create.

Parameters
[in]sizeModeHow the stamp is sized.
See also
PDFStampSizeMode
Parameters
[in]aThe horizontal size component. Meaning depends on sizeMode.
[in]bThe vertical size component. Meaning depends on sizeMode.

◆ SetTextAlignment()

void PDF::Stamper::SetTextAlignment ( PDFStampTextAlign textAlign)
inline

Sets the alignment of multi-line text within a text stamp. Default is kPDFStampTextAlignLeft.

Parameters
[in]textAlignThe text alignment.
See also
PDFStampTextAlign

◆ SetTextOutline()

void PDF::Stamper::SetTextOutline ( PDColorValue strokeColor,
float strokeWidth )
inline

Gives text stamps an outline (stroke), in addition to or instead of the fill.

Parameters
[in]strokeColorThe outline (stroke) color, or kPDColorNone to disable the outline (fill only).
See also
PDColorValue
Parameters
[in]strokeWidthThe outline (stroke) width, in the stamp's coordinate space.
Note
With a fill color (SetFontColor) the text is filled and stroked; when the fill is kPDColorNone it is stroked only. When left unset, text stamps are filled only.

◆ ShowsInLayersPanel()

void PDF::Stamper::ShowsInLayersPanel ( bool inLayersPanel)
inline

Specifies whether the stamp's optional-content layer is registered in the document's layer order (/Order) so it appears in a viewer's layers panel. Default is false.

Parameters
[in]inLayersPanelIf true, the created layer is added to the configuration's /Order.
Note
Has effect only for content stamps that create an optional-content layer (restricted visibility); stamps shown both on screen and print create no layer.

◆ ShowsOnPrint()

void PDF::Stamper::ShowsOnPrint ( bool onPrint)
inline

Specifies whether the stamp is visible when the document is printed. Default is true.

Parameters
[in]onPrintIf true, the stamp is printed.
Note
Print-time behavior is viewer-dependent (content stamps use optional-content /AS; annotation stamps use the annotation print flag).

◆ ShowsOnScreen()

void PDF::Stamper::ShowsOnScreen ( bool onScreen)
inline

Specifies whether the stamp is visible on screen. Default is true.

Parameters
[in]onScreenIf true, the stamp is shown on screen.

◆ StampImage()

void PDF::Stamper::StampImage ( const Document & destDoc,
const Graphics::Bitmap & bitmap,
const std::vector< size_t > & destPages = {} )
inline

Stamps a raster image from an in-memory bitmap onto the given pages.

Parameters
[in]destDocThe document being stamped.
[in]bitmapThe image bitmap to stamp.
[in]destPagesThe zero-based page indices to stamp. Empty means all pages.

◆ StampImageFromFile()

void PDF::Stamper::StampImageFromFile ( const Document & destDoc,
const std::filesystem::path & imagePath,
const std::vector< size_t > & destPages = {} )
inline

Stamps a raster image loaded from a file onto the given pages.

Parameters
[in]destDocThe document being stamped.
[in]imagePathThe path to the image file (.png .jpg .bmp .gif etc.).
[in]destPagesThe zero-based page indices to stamp. Empty means all pages.

◆ StampPage()

void PDF::Stamper::StampPage ( const Document & destDoc,
const Document & srcDoc,
size_t srcPageIndex,
const std::vector< size_t > & destPages = {} )
inline

Stamps a single page from a source PDF document (as vector art) onto the given pages.

Parameters
[in]destDocThe document being stamped.
[in]srcDocThe source PDF document that contains the page to stamp.
[in]srcPageIndexThe zero-based index of the source page in srcDoc.
[in]destPagesThe zero-based page indices to stamp. Empty means all pages.

◆ StampText()

void PDF::Stamper::StampText ( const Document & destDoc,
const std::wstring & text,
const std::vector< size_t > & destPages = {} )
inline

Stamps text onto the given pages using the configured font, color and text alignment.

Parameters
[in]destDocThe document being stamped.
[in]textThe text to stamp.
[in]destPagesThe zero-based page indices to stamp. Empty means all pages.

The documentation for this class was generated from the following file: