How do I read the names and the colorants of every separation inside a PDF page?

135 views
Skip to first unread message

Support

unread,
May 28, 2009, 7:56:30 PM5/28/09
to PDFTron PDFNet SDK
Q: I'd need to read all the separations in a PDF page.
So, if I have a page with 5 colors inside (Cyan, Magenta, Yellow,
Black and Spot) I need to read the names and the colorants of every
separation inside the page.

For example:
Cyan 100,0,0,0
Magenta 0,100,0,0


Spot 0,56,76,34

Is it possible to do?


-------
A: You could use ElementReader to traverse all content on a PDF page
(for an example, please see ElementReaderAdv sample -
http://www.pdftron.com/pdfnet/samplecode.html#ElementReaderAdv).

Depending on a graphical element you encounter there are different
ways to access associated color space properties. For example, for
path/text element you could use element.GetGState().GetStrokeColorSpace
()/GetFillColorSpace(). For an image you would use
element.GetImageColorSpace().

Given a color space you can check its type using cs.GetType() method.
Now I am not sure how your PDFs store separation information but
assuming that you are interested in DeviceN color space
(pdftron::PDF::ColorSpace::e_device_n) you can access its named
colorants as follows:

if (cs.GetType() == ColorSpace::e_device_n) {
// The 'name_array' parameter is an array of name objects
specifying
// the individual colour components.
Obj name_array = cs.GetSDFObj().GetAt(1);
for (int i=0; i<name_array.Size(); ++i) {
string colorant_name = name_array.GetAt(i).GetName();
... print colorant_name ? ...
}
}

Similarly if you encounter a separation color space
(pdftron::PDF::ColorSpace::e_separation) you can access its colorant
name using cs.GetSDFObj().GetAt(1).GetName().

You can obtain colorant values associated with a given color space
using element.GetGState().GetStrokeColor()/GetFillColor() etc. The
colorant are usually floating point numbers in the range [0..1].

Reply all
Reply to author
Forward
0 new messages