PDF SDK Documentation

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

Loading...
Searching...
No Matches
stamper.h File Reference

The PDF Stamper API. More...

#include <pdfsdk/core.h>
#include <pdfsdk/graphics.h>

Go to the source code of this file.

Macros

#define PDF_STAMPER_API   PDFSDK_IMPORT_

Typedefs

typedef struct PDFStamperRec_ * PDFStamper
 The opaque handle to the PDFStamper object.

Enumerations

enum  PDFStampSizeMode { kPDFStampSizeRelative = 1 , kPDFStampSizeAbsolute = 2 , kPDFStampSizeFontSize = 3 }
 Specifies how a stamp is sized. More...
enum  PDFStampHAlign { kPDFStampHAlignLeft = -1 , kPDFStampHAlignCenter = 0 , kPDFStampHAlignRight = 1 }
 Horizontal alignment of the stamp relative to the crop box.
enum  PDFStampVAlign { kPDFStampVAlignBottom = -1 , kPDFStampVAlignCenter = 0 , kPDFStampVAlignTop = 1 }
 Vertical alignment of the stamp relative to the crop box.
enum  PDFStampTextAlign { kPDFStampTextAlignLeft = -1 , kPDFStampTextAlignCenter = 0 , kPDFStampTextAlignRight = 1 }
 Alignment of multi-line text within a text stamp.

Functions

PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperCreate (PDFStampSizeMode sizeMode, float a, float b, PDFStamper *pStamper)
 Creates a new PDFStamper object with an initial size.
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 PDFStamperSetAlignment (PDFStamper stamper, PDFStampHAlign hAlign, PDFStampVAlign vAlign)
 Sets the anchor that the position offset is measured from. Default is centered (kPDFStampHAlignCenter, kPDFStampVAlignCenter).
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 PDFStamperSetOpacity (PDFStamper stamper, float opacity)
 Sets the opacity of the stamp.
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). Default is on top (foreground).
PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperSetAsAnnotation (PDFStamper stamper, bool annotation)
 Specifies whether the stamp is added as a Stamp annotation instead of page content. Default is page content.
PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperShowsOnScreen (PDFStamper stamper, bool onScreen)
 Specifies whether the stamp is visible on screen. Default is true.
PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperShowsOnPrint (PDFStamper stamper, bool onPrint)
 Specifies whether the stamp is visible when the document is printed. Default is true.
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 (/Order) so it appears in a viewer's layers panel. Default is false.
PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperSetName (PDFStamper stamper, const wchar_t *name)
 Sets the stamp name. Default is "Stamp".
PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperSetFont (PDFStamper stamper, const PDFontInfo *fontInfo)
 Sets the font used for text stamps.
PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperSetFontColor (PDFStamper stamper, PDColorValue color)
 Sets the color used for text stamps.
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.
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 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 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 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 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 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 PDFStamperDeleteStamps (PDDoc doc, const PDPageRange *pages)
 Deletes all stamps from the given pages.

Detailed Description

The PDF Stamper API.

The PDF Stamper API stamps PDF pages with text, raster images or vector art (another PDF page) in a few calls. A Stamper is a configuration object: set the size, position, alignment, rotation and opacity once, then call one of the Stamp* functions repeatedly to apply the stamp to a set of pages.

Stamped content is wrapped in a standard PDF marked-content artifact (/Artifact with /Type /Pagination and /Subtype /Watermark) so that it can be located and removed later via PDFStamperHasStamps and PDFStamperDeleteStamps.

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

Typedef Documentation

◆ PDFStamper

typedef struct PDFStamperRec_* PDFStamper

The opaque handle to the PDFStamper object.

Note
The object is reference-counted. Use PDHandleAcquire and PDHandleRelease to manage its lifetime.

Enumeration Type Documentation

◆ PDFStampSizeMode

Specifies how a stamp is sized.

Enumerator
kPDFStampSizeRelative 

Stamp size is relative to the destination page crop box. 'a' is a fraction of the crop box width (0.5 means 50%), 'b' is a fraction of its height. If 'a' <= 0 only 'b' is used; if 'b' <= 0 only 'a' is used (aspect preserved).

kPDFStampSizeAbsolute 

Stamp size is set explicitly in points. 'a' is the width of the stamp bounding box, 'b' is its height, regardless of page size.

kPDFStampSizeFontSize 

Text stamps only. 'a' is the font size in points; 'b' is ignored.

Function Documentation

◆ PDFStamperCreate()

PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperCreate ( PDFStampSizeMode sizeMode,
float a,
float b,
PDFStamper * pStamper )

Creates a new PDFStamper object 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.
[out]pStamperA pointer to a variable that receives the new PDFStamper object.
Returns
A PDErrCode error code.

◆ PDFStamperDeleteStamps()

PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperDeleteStamps ( PDDoc doc,
const PDPageRange * pages )

Deletes all stamps from the given pages.

Parameters
[in]docThe document to delete stamps from.
[in]pagesThe pages to delete stamps from. Pass NULL for all pages.
Returns
A PDErrCode error code.
Note
Only content stamps are removed; annotation stamps (PDFStamperSetAsAnnotation) are not.

◆ PDFStamperHasStamps()

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.

Parameters
[in]docThe document to check.
[in]pagesThe pages to check. Pass NULL to check all pages.
[out]pHasStampsReceives true if at least one stamp is found.
Returns
A PDErrCode error code.
Note
Only content stamps are detected; annotation stamps (PDFStamperSetAsAnnotation) are not.

◆ PDFStamperSetAlignment()

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, kPDFStampVAlignCenter).

Parameters
[in]stamperThe PDFStamper object.
[in]hAlignHorizontal anchor.
See also
PDFStampHAlign
Parameters
[in]vAlignVertical anchor.
See also
PDFStampVAlign
Returns
A PDErrCode error code.

◆ PDFStamperSetAsAnnotation()

PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperSetAsAnnotation ( PDFStamper stamper,
bool annotation )

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 PDFStamperHasStamps / PDFStamperDeleteStamps.

Parameters
[in]stamperThe PDFStamper object.
[in]annotationIf true, the stamp is added as a Stamp annotation; otherwise into the page content.
Returns
A PDErrCode error code.

◆ PDFStamperSetAsBackground()

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). Default is on top (foreground).

Parameters
[in]stamperThe PDFStamper object.
[in]backgroundIf true, the stamp is inserted as a background layer; otherwise on top.
Returns
A PDErrCode error code.
Note
Ignored for annotation stamps (PDFStamperSetAsAnnotation).

◆ PDFStamperSetFont()

PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperSetFont ( PDFStamper stamper,
const PDFontInfo * fontInfo )

Sets the font used for text stamps.

Parameters
[in]stamperThe PDFStamper object.
[in]fontInfoThe font description (family, format, style).
See also
PDFontInfo
Returns
A PDErrCode error code.
Note
When left unset, text stamps default to kPDAtom_Helvetica with kPDFontStyleRegular in black.
The font size is controlled by PDFStamperSetSize with kPDFStampSizeFontSize.

◆ PDFStamperSetFontColor()

PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperSetFontColor ( PDFStamper stamper,
PDColorValue color )

Sets the color used for text stamps.

Parameters
[in]stamperThe PDFStamper object.
[in]colorThe font color.
See also
PDColorValue
Returns
A PDErrCode error code.
Note
When left unset, text stamps default to black.

◆ PDFStamperSetName()

PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperSetName ( PDFStamper stamper,
const wchar_t * name )

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]stamperThe PDFStamper object.
[in]nameThe name, in wide character string format.
Returns
A PDErrCode error code.

◆ PDFStamperSetOpacity()

PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperSetOpacity ( PDFStamper stamper,
float opacity )

Sets the opacity of the stamp.

Parameters
[in]stamperThe PDFStamper object.
[in]opacityThe opacity in the range [0, 1], where 1 is fully opaque. Default is 1.
Returns
A PDErrCode error code.

◆ PDFStamperSetPosition()

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).

Parameters
[in]stamperThe PDFStamper object.
[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.
Returns
A PDErrCode error code.

◆ PDFStamperSetRotation()

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).

Parameters
[in]stamperThe PDFStamper object.
[in]degreesThe rotation in degrees.
Returns
A PDErrCode error code.

◆ PDFStamperSetSize()

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.

Parameters
[in]stamperThe PDFStamper object.
[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.
Returns
A PDErrCode error code.

◆ PDFStamperSetTextAlignment()

PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperSetTextAlignment ( PDFStamper stamper,
PDFStampTextAlign textAlign )

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

Parameters
[in]stamperThe PDFStamper object.
[in]textAlignThe text alignment.
See also
PDFStampTextAlign
Returns
A PDErrCode error code.

◆ PDFStamperSetTextOutline()

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.

Parameters
[in]stamperThe PDFStamper object.
[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.
Returns
A PDErrCode error code.
Note
With a fill color (PDFStamperSetFontColor) the text is filled and stroked; when the fill is kPDColorNone it is stroked only. When left unset, text stamps are filled only.

◆ PDFStamperShowsInLayersPanel()

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 (/Order) so it appears in a viewer's layers panel. Default is false.

Parameters
[in]stamperThe PDFStamper object.
[in]inLayersPanelIf true, the created layer is added to the configuration's /Order.
Returns
A PDErrCode error code.
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.

◆ PDFStamperShowsOnPrint()

PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperShowsOnPrint ( PDFStamper stamper,
bool onPrint )

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

Parameters
[in]stamperThe PDFStamper object.
[in]onPrintIf true, the stamp is printed.
Returns
A PDErrCode error code.
Note
Print-time behavior is viewer-dependent (content stamps use optional-content /AS; annotation stamps use the annotation print flag).

◆ PDFStamperShowsOnScreen()

PDFSDK_IMPORT_ PDErrCode PDFSDK_CALLCONV PDFStamperShowsOnScreen ( PDFStamper stamper,
bool onScreen )

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

Parameters
[in]stamperThe PDFStamper object.
[in]onScreenIf true, the stamp is shown on screen.
Returns
A PDErrCode error code.

◆ PDFStamperStampImage()

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.

Parameters
[in]stamperThe PDFStamper object.
[in]destDocThe document being stamped.
[in]bitmapThe image bitmap to stamp.
[in]destPagesThe pages to stamp. Pass NULL to stamp all pages.
Returns
A PDErrCode error code.

◆ PDFStamperStampImageFromFile()

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.

Parameters
[in]stamperThe PDFStamper object.
[in]destDocThe document being stamped.
[in]imagePathThe path to the image file (.png .jpg .bmp .gif etc.).
[in]destPagesThe pages to stamp. Pass NULL to stamp all pages.
Returns
A PDErrCode error code.

◆ PDFStamperStampPage()

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.

Parameters
[in]stamperThe PDFStamper object.
[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 pages to stamp. Pass NULL to stamp all pages.
Returns
A PDErrCode error code.

◆ PDFStamperStampText()

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.

Parameters
[in]stamperThe PDFStamper object.
[in]destDocThe document being stamped.
[in]textThe text to stamp, in wide character string format.
[in]destPagesThe pages to stamp. Pass NULL to stamp all pages.
Returns
A PDErrCode error code.