set_option("searchpath={" . $searchpath . "}"); /* This means we must check return values of load_font() etc. */ $p->set_option("errorpolicy=return"); /* Set an output path according to the name of the topic */ if ($p->begin_document($outfile, "") == 0) throw new Exception("Error: " . $p->get_errmsg()); $p->set_info("Creator", "PDFlib Cookbook"); $p->set_info("Title", $title ); /* Create an A4 Landscape page */ $p->begin_page_ext(0, 0, "width=a4.height height=a4.width"); /* --------------------------------------------------------------------- * Output text which does not contain any options to avoid line breaking * --------------------------------------------------------------------- */ $text = "For more information about the Giant Wing Paper Plane see " . "our Web site www.kraxi-systems.com" . ".Alternatively, contact us by email " . "via questions@kraxi-systems.com" . ". You'll get all information about how to fly " . "the Giant Wing in a thunderstorm as soon as possible."; $p->fit_textline("Text without any options to avoid line breaking", 50, 430, "fontname=NotoSerif-Bold fontsize 12"); /* Create the Textflow from the $text */ $optlist = "fontname=NotoSerif-Regular fontsize=20 " . "leading=140%"; $tf = $p->create_textflow($text, $optlist); if ($tf == 0) throw new Exception("Error: " . $p->get_errmsg()); $result = $p->fit_textflow($tf, 50, 100, 300, 400, "fitmethod=auto showborder"); if (!$result == "_stop") { /* Check for errors */ } $p->delete_textflow($tf); /* -------------------------------------------------------------- * Output the same $text but with additional options to avoid line * breaking * -------------------------------------------------------------- */ /* Text containing options to avoid any line breaking in the Web * address with "..." and to avoid any line * breaking after the "-" and "." characters in the email address with * "charclass={letter {- .}}>...". */ $text_avoid = "For more information about the Giant Wing Paper Plane " . "see our Web site " . "www.kraxi-systems.com." . "Alternatively, contact us by email via questions@kraxi-systems.com" . ". You'll get all " . "information about how to fly the Giant Wing in a thunderstorm " . "as soon as possible."; $p->fit_textline("Text with \"charclass\" and \"avoidbreak\" options", 450, 430, "fontname=NotoSerif-Bold fontsize=12"); /* Create the Textflow from the $text */ $tf_avoid = $p->create_textflow($text_avoid, $optlist); if ($tf_avoid == 0) throw new Exception("Error: " . $p->get_errmsg()); $result = $p->fit_textflow($tf_avoid, 450, 100, 700, 400, "fitmethod=auto showborder"); if (!$result == "_stop") { /* Check for errors */ } $p->delete_textflow($tf_avoid); $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=avoid_linebreaking.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; ?>