API reference › PDF/A & Conformance
pdfApplyPattern
Set the current fill or stroke color to an already-created
BOOL32 __stdcall pdfApplyPattern(PPDF IPDF, int32_t PattHandle, TColorMode ColorMode, uint32_t Color);
BOOL32 __stdcall pdfApplyShading(PPDF IPDF, int32_t ShadHandle);
function pdfApplyPattern(const IPDF: PPDF; PattHandle: Integer; ColorMode: TColorMode; Color: Cardinal): LongBool; stdcall;
function pdfApplyShading(const IPDF: PPDF; ShadHandle: Integer): LongBool; stdcall;
Purpose. Set the current fill or stroke color to an already-created pattern or shading (both must have been created earlier via the pattern/shading creation APIs, Patterns, Shadings, ExtGState Creation, and Template Placement) — the "select this pattern as the active paint" step, emitting the actual content-stream operators.
Description. Both are genuinely real, emitting real PDF content operators immediately. pdfApplyShading writes /Pattern colorspace-select is not needed for sh — it directly calls WriteShading, which emits the sh operator naming the shading resource. pdfApplyPattern selects /Pattern as the fill (cs/scn) or stroke (CS/SCN) color space based on ColorMode (1 = cmStroke, else fill), then names the pattern resource via scn/SCN — **and, for an *uncolored* tiling pattern (PaintType = 2), correctly prepends the underlying RGB components before the pattern name** (r g b /PatName scn, per the PDF spec's requirement that uncolored patterns supply their paint color as extra SCN operands) — a real, correctly-implemented spec nuance, not merely always emitting the colored-pattern form.
Parameters.
| Parameter | Description |
|---|---|
IPDF | Document handle. |
PattHandle / ShadHandle | The pre-created pattern/shading handle. |
ColorMode | *(Pattern only)* cmStroke selects the stroke color space; anything else selects fill. |
Color | *(Pattern only)* Underlying paint color — only used (and required) for uncolored (PaintType 2) patterns. |
Return value. True if the handle resolves to a real pattern/shading and there's an active content stream to write into.
C# (P/Invoke)
[return: MarshalAs(UnmanagedType.Bool)]
Core
pdfApplyPattern
The …A form takes UTF-8, …W
takes UTF-16; a bare name aliases the ANSI form.
Worked examples — complete programs in ten languages.