API referenceGraphics

pdfConvertColors

Rewrite every page's content stream, converting RGB/CMYK color

C
int32_t __stdcall pdfConvertColors(PPDF IPDF, TColorConvFlags Flags, float* Add);
Delphi
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.

ParameterDescription
IPDFDocument handle.
FlagsAccepted but never read — has no effect on the conversion performed.
AddAccepted 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)

wrappers/dotnet/LumasPdf.cs
public static extern int pdfConvertColors(IntPtr IPDF, uint Flags, float[] Add);
Area
Graphics
Category

Conversion

Exported names

pdfConvertColors

String variants

The …A form takes UTF-8, …W takes UTF-16; a bare name aliases the ANSI form.

See working code

Worked examples — complete programs in ten languages.