set_option("errorpolicy=return"); if ($p->begin_document("", "") == 0) { throw new Exception("Error: " . $p->get_errmsg()); } $p->set_option("searchpath={" . $searchpath . "}"); $p->set_info("Creator", "PDFlib Cookbook"); $p->set_info("Title", $title ); /* Load split channel images and colorize with a suitable spot color */ for ($channel = 0; $channel < $MAXCHANNEL; $channel++) { $p->setcolor("fill", "cmyk", $alt[$channel][0], $alt[$channel][1], $alt[$channel][2], $alt[$channel][3]); $spot[$channel] = $p->makespotcolor($channelnames[$channel]); $filename = $basename . $channelsuffix[$channel] . "." . $suffix; $optlist = "colorize=" . $spot[$channel]; $image[$channel] = $p->load_image("auto", $filename, $optlist); if ($image[$channel] == 0) { throw new Exception("Error: " . $p->get_errmsg()); } } /* Set suitable blend mode for overlaying the images */ $gs = $p->create_gstate("blendmode=Darken"); /* Page size may be adjusted by PDF_fit_image() */ $p->begin_page_ext(0, 0, "width=a4.width height=a4.height transparencygroup={colorspace=DeviceCMYK}"); $p->save(); $p->set_gstate($gs); for ($channel = 0; $channel < $MAXCHANNEL; $channel++) { $p->fit_image($image[$channel], 0.0, 0.0, "adjustpage"); $p->close_image($image[$channel]); } $p->restore(); $p->end_page_ext(""); $p->end_document(""); $buf = $p->get_buffer(); $len = strlen($buf); header("Content-type: application/pdf"); header("Content-Length: $len"); header("Content-Disposition: inline; filename=recombine_color_channels.pdf"); print $buf; } catch (PDFlibException $e) { echo("PDFlib exception occurred:\n". "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . $e->get_errmsg() . "\n"); exit(1); } catch (Throwable $e) { echo("PHP exception occurred: " . $e->getMessage() . "\n"); exit(1); } $p = 0; ?>