set_option("searchpath={" . $searchpath . "}"); $p->set_option("searchpath={" . $fontpath . "}"); /* This means we must check return values of load_font() etc. */ $p->set_option("errorpolicy=return"); if ($p->begin_document($outfile, "") == 0) throw new Exception("Error: " . $p->get_errmsg()); $p->set_info("Creator", "PDFlib Cookbook"); $p->set_info("Title", $title); /* Load page of the input PDF document */ $doc = $p->open_pdi_document($infile, ""); if ($doc == 0) throw new Exception("Error: " . $p->get_errmsg()); $page = $p->open_pdi_page($doc, 1, ""); if ($page == 0) throw new Exception("Error: " . $p->get_errmsg()); /* -------------------------------------------------------- * Place imported page at the lower left corner of the page * -------------------------------------------------------- */ $p->begin_page_ext(0, 0, "width=a4.height height=a4.width"); /* Place PDF page in lower left corner */ $p->fit_pdi_page($page, 0, 0, ""); $p->end_page_ext(""); /* -------------------------------------------------------- * Output the page at the with a shift of the page * -------------------------------------------------------- */ $p->begin_page_ext(0, 0, "width=a4.height height=a4.width"); /* Place PDF page in its original size, but shift it to the right and up */ $p->fit_pdi_page($page, $shift_x, $shift_y, ""); $p->end_page_ext(""); $p->close_pdi_page($page); $p->close_pdi_document($doc); $p->end_document(""); /* * Return the sub-document to the user. If all split documents are to * be processed, do something different, e.g. write the documents * to disk and create an HTML page with a list of links for the * sub-documents. */ $buf = $p->get_buffer(); $len = strlen($buf); header("Content-type: application/pdf"); header("Content-Length: $len"); header("Content-Disposition: inline; filename=" . $outfile); 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($e); exit(1); } $p = 0; ?>