Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old


Converts colors to gray.

Component Version macOS Windows Linux Server iOS SDK
DynaPDF 9.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "DynaPDF.ConvertColors"; PDF; Flags { ; Add } )   More


Parameter Description Example Flags
PDF The PDF reference returned from DynaPDF.New. $pdf
Flags The mode to operate.
Can be BW_To_Gray (RGB and B/W to gray), RGB_To_Gray (RGB to gray), ToGrayAdjust (Lighten or darken colors).
Add The value for ToGrayAdjust flag. 1.0 Optional


Returns OK or error.


Converts colors to gray.
The function converts inline RGB operators in the current open page to gray. At time of publication only inline operators like g, rg, G, and RG are processed. CMYK colors will be left unchanged. The parameter Add is optional and considered only if the constant ToGrayAdjust is used.
The conversion of RGB inline color operators can be useful if the document was created with a GDI application, e.g. Microsoft Word, Excel and so on and if the file must be split into black & white and color pages. DynaPDF.IsColorPage can then be used to determine whether the page contains still colored objects. The advantage is that RGB black & white values, which are used for text and vector graphics, are already removed so that DyanPDF.IsColorPage returns only true if any other object uses a color, e.g. an image.
The constant ToGrayAdjust can be used to convert RGB colors to gray and to darken or lighten RGB and gray colors. The parameter Add must be a pointer of a floating point variable. The value can be in the range -1.0 through 1.0. Colors in PDF are stored as floating point values in the range 0.0 through 1.0. Since DeviceGray is an additive color space, 0 denotes black and 1.0 white. If all color operators should be set to black for example, then set the variable to -1.0. The function performs a range check. If the color becomes out of range then it will be adjusted to the nearest value that is inside the allowed color range.

See also ConvertColors function in DynaPDF manual.

See also

Release notes

Blog Entries

This function checks for a license.

Created 17th April 2019, last changed 17th April 2019

DynaPDF.CloseTag - DynaPDF.ConvertStyledText