pdfConvertColors
Rewrite every page's content stream, converting RGB/CMYK color
int32_t __stdcall pdfConvertColors(PPDF IPDF, TColorConvFlags Flags, float* Add);
function pdfConvertColors(const IPDF: PPDF; Flags: TColorConvFlags; Add: PSingle): Integer; stdcall;
Purpose. Rewrite every page's content stream, converting RGB/CMYK color operators to grayscale in place.
Description. For every page, parses the content stream (TPsrContentParser), and for each rg/RG (RGB) or k/K (CMYK) color-setting operator found, computes a luminance-weighted gray value (0.299R + 0.587G + 0.114B, converting CMYK to RGB first via the standard formula) and rewrites the operator in place to g/G with the single gray operand — then re-serializes and stores the modified content stream back onto the page. Both ABI parameters are dead: Flags (a TColorConvFlags set that would presumably select which conversion mode/color spaces to target) and Add (a float array that would presumably be an additive color-correction offset) are never referenced anywhere in the function body — the conversion always unconditionally targets RGB/CMYK→Gray regardless of what Flags requests, and Add has zero effect on the output. Also does not touch sc/scn/SC/SCN (Separation/DeviceN/ICC tint) operators, g/G (already-gray) operators, or image XObject color data — only literal rg/RG/k/K device-color operators are rewritten.
Parameters.
| Parameter | Description |
|---|---|
IPDF | Document handle. |
Flags | Accepted but never read — has no effect on the conversion performed. |
Add | Accepted but never read — has no effect on the conversion performed. |
Return value. The total number of rg/RG/k/K operators rewritten across every page (0 if IPDF is invalid or none were found).
Remarks. Despite the ABI's TColorConvFlags parameter suggesting selectable behavior (e.g. converting to a target other than gray, or restricting to certain pages/spaces), the actual implementation performs exactly one fixed transform (RGB/CMYK → luminance gray, whole document) no matter what is passed.
See also. pdfConvColor.
C# (P/Invoke)
public static extern int pdfConvertColors(IntPtr IPDF, uint Flags, float[] Add);
Conversion
pdfConvertColors
The …A form takes UTF-8, …W
takes UTF-16; a bare name aliases the ANSI form.
Worked examples — complete programs in ten languages.