set_option("searchpath={" . $searchpath . "}"); /* This means we must check return values of load_font() etc. */ $p->set_option("errorpolicy=return"); if ($p->begin_document("", "") == 0) throw new Exception("Error: " . $p->get_errmsg()); $p->set_info("Creator", "PDFlib Cookbook"); $p->set_info("Title", $title); /* * The transparency group colorspace is important for Overprint * Preview on the screen. */ $p->begin_page_ext(0, 0, "width=a4.width height=a4.height transparencygroup={colorspace=devicecmyk}"); $font = $p->load_font("NotoSerif-Regular", "unicode", ""); if ($font == 0) throw new Exception("Error: " . $p->get_errmsg()); $p->setfont($font, 11); /* * ******************************************************* * Yellow and Cyan in CMYK color space without overprinting */ $p->set_graphics_option("fillcolor={cmyk 1 0 0 0}"); $p->rect($x, $y, $width, $height); $p->fill(); $optlist = "overprintfill=false"; $gstate = $p->create_gstate($optlist); $p->save(); $p->set_gstate($gstate); $p->set_graphics_option("fillcolor={cmyk 0 0 1 0}"); $p->rect($x + $width / 2, $y + $height / 2, $width, $height); $p->fill(); $p->restore(); $p->fit_textline("CMYK colors without overprinting: " . $optlist, $x, $y - 2 * $fontsize, "fillcolor=black"); /* * ******************************************************* * Overprint Yellow and Cyan in CMYK color space: this is * device-dependent; it requires "Overprint Preview" enabled in * Acrobat. */ $y -= 2 * $height; $p->set_graphics_option("fillcolor={cmyk 1 0 0 0}"); $p->rect($x, $y, $width, $height); $p->fill(); $optlist = "overprintfill=true overprintmode=1"; $gstate = $p->create_gstate($optlist); $p->save(); $p->set_gstate($gstate); $p->set_graphics_option("fillcolor={cmyk 0 0 1 0}"); $p->rect($x + $width / 2, $y + $height / 2, $width, $height); $p->fill(); $p->restore(); $p->fit_textline("Device-dependent overprinting: " . $optlist, $x, $y - 2 * $fontsize, "fillcolor=black"); /* * ******************************************************* * Achieve device-independent overprinting effect with Yellow and * Cyan in CMYK color space with blend mode "Darken". */ $y -= 2 * $height; $p->set_graphics_option("fillcolor={cmyk 1 0 0 0}"); $p->rect($x, $y, $width, $height); $p->fill(); $optlist = "blendmode=darken"; $gstate = $p->create_gstate($optlist); $p->save(); $p->set_gstate($gstate); $p->set_graphics_option("fillcolor={cmyk 0 0 1 0}"); $p->rect($x + $width / 2, $y + $height / 2, $width, $height); $p->fill(); $p->restore(); $p->fit_textline( "Device-independent overprinting effect with blend mode: " . $optlist, $x, $y - 2 * $fontsize, "fillcolor=black"); /* * ******************************************************* * Overprint Yellow and Cyan in DeviceN color space: overprint * settings don't have any effect. */ $y -= 2 * $height; $devicen = $p->create_devicen( "names={Cyan Yellow} alternate=devicecmyk transform={{0 0 3 1 roll}} errorpolicy=exception"); $p->set_graphics_option("fillcolor={devicen " . $devicen . " 1 0}"); $p->rect($x, $y, $width, $height); $p->fill(); $gstate = $p->create_gstate("overprintfill=true overprintmode=1"); $p->save(); $p->set_gstate($gstate); $p->set_graphics_option("fillcolor={devicen " . $devicen . " 0 1}"); $p->rect($x + $width / 2, $y + $height / 2, $width, $height); $p->fill(); $p->restore(); $p->fit_textline( "DeviceN colors (Cyan+Yellow): always unaffected by overprint settings", $x, $y - 2 * $fontsize, "fillcolor=black"); $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=overprint.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; ?>