int32_t __stdcall pdfIsColorPage(PPDF IPDF, BOOL32 GrayIsColor);
function pdfIsColorPage(const IPDF: PPDF; GrayIsColor: LongBool): Integer; stdcall;
Purpose. Test whether the current page's content stream contains any non-gray color-setting operators, without rendering the page.
Description. Scans the current page's content-stream tokens for color-setting operators and inspects their operands directly (no rasterization occurs): rg/RG (RGB) counts as color if any two of the three components differ by more than a small epsilon; k/K (CMYK) counts as color if any of C/M/Y exceeds the epsilon (i.e. any non-zero process-color ink beyond pure K); sc/scn/SC/SCN (Separation/DeviceN/Pattern tint) with 3 components uses the same RGB-divergence test, with 4 components uses the same CMYK test, and with any other component count (typically 1, a grayscale-or-single-colorant tint) is never counted as color regardless of value; g/G (explicit gray) counts as color only when GrayIsColor is True and the value is strictly between 0 and 1 (pure black or pure white gray is never counted even with GrayIsColor set). This is a pure text/operand scan — it does not account for color introduced by embedded images, patterns, or shadings referenced from the content stream.
Parameters.
| Parameter | Description |
|---|---|
IPDF | Document handle. |
GrayyIsColor | Whether a non-pure gray value (g/G strictly between 0 and 1) should itself count as "color." |
Return value. 1 = color content found; 0 = monochrome (no qualifying color operator found); -1 = no current page.
Remarks. Because this only inspects color *operators*, a page whose only color comes from an embedded color image or a Separation/DeviceN pattern fill with a non-3/4-component tint will be reported as monochrome even though it visually renders in color.
C# (P/Invoke)
public static extern int pdfIsColorPage(IntPtr IPDF, [MarshalAs(UnmanagedType.Bool)] bool GrayIsColor);
Core
pdfIsColorPage
The …A form takes UTF-8, …W
takes UTF-16; a bare name aliases the ANSI form.
Worked examples — complete programs in ten languages.