RecolorDocument
Colour
Description
Moves every page of the document into one colour space.
Syntax
Delphi
Function TPDFlib.RecolorDocument(TargetSpace: Integer): Integer;Parameters
| TargetSpace | 1 grey, 2 RGB, 3 CMYK. |
|---|
Return values
| Count | How many colours were converted across the whole document. |
|---|---|
| 0 | Nothing needed converting, or TargetSpace was outside 1 to 3. A page whose colours are already in the target space keeps its original bytes. |
Remarks
The conversion is the ordinary device arithmetic rather than a colour-managed one: a document that says only DeviceRGB carries no profile to convert through. RGB becomes grey by the luminance weights of ITU-R BT.601, and CMYK converts as described in ISO 32000-1 §8.6.4.4, which is what a viewer already does when it shows a CMYK document on a screen.
Colours set through an ICCBased, Separation, Indexed or Pattern space are left as they stand. Reading their components without their profile would change how the page looks rather than keep it, so such a document is converted only in the parts that name a device space directly.
The images a page draws are converted too, when the image carries eight bits a component, a device colour space, and either no compression or plain Flate. A JPEG or fax image would have to be re-encoded, which is a different operation from converting its colours, so it keeps its own bytes.
An indexed image is converted through its colour table instead, so its samples keep the indices they already held. That path does not care how the samples are packed or compressed, which is how a palette screenshot or chart converts even though its samples could not be rewritten.
Gradients are converted with the functions behind them, so the space and the stops always agree. A gradient built from a sampled or PostScript function keeps its own colours, as do the mesh shading types, which carry their colours in a stream rather than in a function.
Soft masks and stencil masks are left alone. Both are read as coverage rather than as colour, and converting one would leave the page showing the mask as a picture.
Geometry, text, clipping and every other operator are written back unchanged.
The selected page is restored when the call returns.
Example
// Send a mixed-colour document to a press that expects CMYK
PDF.LoadFromFile('brochure.pdf', '');
Converted := PDF.RecolorDocument(3);
PDF.SaveToFile('brochure-cmyk.pdf');