set_option("searchpath={" . $searchpath . "}"); /* This means we must check return values of load_font() etc. */ $p->set_option("errorpolicy=return"); $p->set_option("stringformat=utf8"); if ($p->begin_document($outfile, "") == 0) throw new Exception("Error: " . $p->get_errmsg()); $p->set_info("Creator", "PDFlib Cookbook"); $p->set_info("Title", $title); /* Start Page */ $p->begin_page_ext(0, 0, "width=a4.width height=a4.height"); /* Load the font */ $font = $p->load_font("NotoSerif-Regular", "unicode", ""); if ($font == 0) throw new Exception("Error: " . $p->get_errmsg()); /* Place a text line with a simulated italic angle of -12. The * characters will be slanted by 12 degrees to the right. */ $optlist = "font=" . $font . " fontsize=20 " . "italicangle=-12"; $p->fit_textline($textline . " (italicangle=-12)", 100, 750, $optlist); /* Place a text line with a simulated bold font style */ $optlist = "font=" . $font . " fontsize=20 " . "fakebold=true"; $p->fit_textline($textline . " (fakebold=true)", 100, 650, $optlist); /* Place a Textflow with a simulated italic angle of -12. The * characters will be slanted by 12 degrees to the right. */ $optlist = "font=" . $font . " fontsize=20 italicangle=-12"; $tf = $p->add_textflow(0, "(italicangle=-12)\n" . $textflow, $optlist); if ($tf == 0) throw new Exception("Error: " . $p->get_errmsg()); $result = $p->fit_textflow($tf, 100, 350, 450, 550, ""); if (!$result == "_stop") { /* Check for errors or more text to be placed */ } $p->delete_textflow($tf); /* Place a Textflow with a simulated bold font style */ $optlist = "font=" . $font . " fontsize=20 fakebold=true"; $tf = $p->add_textflow(0, "(fakebold=true)\n" . $textflow, $optlist); if ($tf == 0) throw new Exception("Error: " . $p->get_errmsg()); $result = $p->fit_textflow($tf, 100, 100, 450, 300, ""); if (!$result == "_stop") { /* Check for errors or more text to be placed */ } $p->delete_textflow($tf); $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=simulated_fontstyles.pdf"); print $buf; } catch (PDFlibException $e) { echo("PDFlib exception occurred:\n". "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . $e->get_errmsg() . "\n"); exit(1); } catch (Exception $e) { echo($e->getMessage()); exit(1); } $p = 0; ?>