set_option("errorpolicy=return"); $p->set_option("searchpath={" . $searchpath . "}"); $p->set_option("stringformat=utf8"); if ($p->begin_document("", "pdfx=PDF/X-5g") == 0) { throw new Exception("Error: " . $p->get_errmsg()); } $p->set_info("Creator", "PDFlib starter sample"); $p->set_info("Title", "starter_pdfx5g"); /* Open the output intent profile */ if ($p->load_iccprofile("ISOcoated_v2_eci.icc", "usage=outputintent") == 0) { print("Error: " . $p->get_errmsg() . "\n"); print("See www.pdflib.com for output intent ICC profiles.\n"); $p->delete(); return(2); } /* Font embedding is required for PDF/X */ $font = $p->load_font("NotoSerif-Regular", "unicode", "embedding"); if ($font == 0) { throw new Exception("Error: " . $p->get_errmsg()); } /* * Create a template which will serve as proxy. The referenced page * (the target) is attached to the proxy. The width and height * The template width and height will be determined automatically, * so we don't have to supply them. */ $optlist = "reference={filename=" . $targetname . " pagenumber=1}"; $proxy = $p->begin_template_ext(0, 0, $optlist); if ($proxy == 0) { throw new Exception("Error: " . $p->get_errmsg()); } $width = $p->info_image($proxy, "imagewidth", ""); $height = $p->info_image($proxy, "imageheight", ""); /* * Draw a crossed-out rectangle to visualize the proxy. Attention: * if we use the exact corner points, one half of the linewidth * would end up outside the template, and therefore be clipped. */ $p->setlinewidth($linewidth); $p->moveto($linewidth / 2, $linewidth / 2); $p->lineto($width - $linewidth / 2, $linewidth / 2); $p->lineto($width - $linewidth / 2, $height - $linewidth / 2); $p->lineto($linewidth / 2, $height - $linewidth / 2); $p->lineto($linewidth / 2, $linewidth / 2); $p->lineto($width - $linewidth / 2, $height - $linewidth / 2); $p->moveto($width - $linewidth / 2, $linewidth / 2); $p->lineto($linewidth / 2, $height - $linewidth / 2); $p->stroke(); $p->setfont($font, 24); $optlist = "fitmethod=auto position=center boxsize={" . $width . " " . $height . "}"; $p->fit_textline("Proxy replaces target here", 0, 0, $optlist); $p->end_template_ext(0, 0); /* Create the page */ $p->begin_page_ext(0, 0, "width=a4.width height=a4.height"); $p->setfont($font, 18); $p->fit_textline( "PDF/X-5 starter sample with reference to an external page", 50, 700, ""); /* Place the proxy on the page */ $p->fit_image($proxy, 50, 50, "boxsize={500 500} fitmethod=meet"); $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=starter_pdfx5g.pdf"); print $buf; } catch (PDFlibException $e) { echo("PDFlib exception occurred in starter_pdfx5g sample:\n" . "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . $e->get_errmsg() . "\n"); exit(1); } catch (Exception $e) { echo($e); exit(1); } $p = 0; ?>