DynaPDF Manual - Page 226

Previous Page 225   Index   Next Page 227

Function Reference
Page 226 of 839
ConvertColors
Syntax:
LBOOL pdfConvertColors(
const PPDF* IPDF,
// Instance pointer
TColorConvFlags Flags, // See below
const float* Add)
// Optional, see description below
typedef enum
{
ccfBW_To_Gray
= 0, // Default, RGB B/W to gray
ccfRGB_To_Gray
= 1, // RGB to gray
ccfToGrayAdjust = 2
// Lighten or darken colors
}TColorConvFlags;
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 ccfToGrayAdjust 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. 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 IsColorPage() returns only true if any other object uses a
color, e.g. an image.
The constant ccfToGrayAdjust 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.
Example (C++):
// This example converts all RGB and gray colors to black.
pdfEditPage(PDF, 1);
float add = -1.0;
pdfConvertColors(PDF, ccfToGrayAdjust, &add);
pdfEndPage(PDF);
Return values:
If the function succeeds the return value is 1. If the function fails the return value is 0.
 

Previous topic: ConvColor

Next topic: ConvertEMFSpool