Ney LS
Ney LS

Reputation: 27

PDFLib detect RGB colors in object then convert it to CMYK

I am importing a pdf file to a page using PDFLib. How can I detect if RGB color is used on the objects within the file that I am importing then convert them to CMYK?

Below is my php code.

$p = new PDFlib();
$raw= $p->open_pdi_document($working_folder.$raw_file,"");
$page1= $p->open_pdi_page($raw,1,"");

$p->set_option("errorpolicy=exception");
$p->begin_document("", "");
$p->begin_page_ext(0,0,"width=".$width." height=".$height.")";
$p->fit_pdi_page($page1,0,0,"");
$p->end_document("");`

My goal is to detect RGB colors in $raw and convert them to CMYK when I call fit_pdi_page.

Upvotes: 0

Views: 86

Answers (1)

Rainer
Rainer

Reputation: 2185

My goal is to detect RGB colors in $raw and convert them to CMYK when I call fit_pdi_page.

this is no functionality, which PDFlib+PDI offer.

When you import a PDF page, the page is a "black box" for PDI. So, you can place it as you want, but you do not have any access to the content of the page. (see PDFlib 10.0.2 Tutorial, chapter 8.3.2 "Using PDFlib+PDI")

with the pCOS interface of PDFlib+PDI you can determine, which colorspace are defined on a page. This is demonstrated in the pCOS Cookbook cookbook: https://www.pdflib.com/pcos-cookbook/pages/page_colorspaces/

But please get in mind, this do not detect, if the page really use a color from the colorspace. Just if the colorspace is defined.

You should check before loading the PDF document, if this fit your needs and do the color space conversion. Sorry, for this task, I couldn't recommend any tool.

Upvotes: 1

Related Questions