set_option("SearchPath=" . $searchpath); /* This means we must check return values of load_font() etc. */ $p->set_option("errorpolicy=return"); /* * Open the document. "tagged=true" opens the document in Tagged PDF * mode. "lang=en" indicated the predominant document language as * English. */ if ($p->begin_document("", "pdfua=PDF/UA-1 lang=en " . "tag={tagname=Document Title={Flyer}}") == 0) throw new Exception("Error: " . $p->get_errmsg()); $p->set_info("Creator", "PDFlib Cookbook"); $p->set_info("Title", $title); /* Load the font */ $font = $p->load_font("NotoSerif-Regular", "unicode", ""); if ($font == 0) throw new Exception("Error: " . $p->get_errmsg()); /* Force automatic word breaks */ $p->set_option("autospace=true"); /* Feed the first text to the first Textflow object */ $tf1 = $p->add_textflow($tf1, $text1, $optlist); if ($tf1 == 0) throw new Exception("Error: " . $p->get_errmsg()); /* Feed the second text to the second Textflow object */ $tf2 = $p->add_textflow($tf2, $text2, $optlist); if ($tf2 == 0) throw new Exception("Error: " . $p->get_errmsg()); /* Start the first page */ $p->begin_page_ext($width, $height, ""); /* * Open a structure element of type "Section" for all text contents * to be included. */ $id_sect = $p->begin_item("Sect", "Title = {Topic}"); /* Open a structure element of type "H1" */ $p->setfont($font, 20); $p->fit_textline("Our Paper Planes", $llx, $ury + 20, "tag={tagname=H1 Title = {Intro}}"); /* Create a bookmark for the header */ $p->create_bookmark("Our Paper Planes", ""); /* * Open a structure element of type "P" for the first Textflow to be * included. All parts of the Textflow, i.e. all calls to * PDF_fit_textflow() with the specific Textflow handle, should be * contained in a single structure element. */ $id_p = $p->begin_item("P", "Title = {Description}"); /* * Loop until all of the text is placed; create new pages as long as * more text needs to be placed. */ do { $result = $p->fit_textflow($tf1, $llx, $lly, $urx, $ury, "linespreadlimit=140%"); $p->end_page_ext(""); /* Start a new page */ $p->begin_page_ext($width, $height, ""); } while ($result == "_boxfull" || $result == "_nextpage"); /* Fit the second Textflow */ $result = $p->fit_textflow($tf2, $llx, $lly, $urx, $ury, "linespreadlimit=140%"); /* Close the structure element of type "P" */ $p->end_item($id_p); $p->fit_textline("Read more ...", $llx, $lly - 20, "tag={tagname=P} fontsize=20 font=" . $font); $p->end_page_ext(""); /* Close the structure element of type "Section" */ $p->end_item($id_sect); /* Check for errors */ if ($result != "_stop") { /* * "_boxempty" happens if the box is very small and doesn't hold * any text at all. */ if (result == "_boxempty") throw new Exception("Error: Textflow box too small"); else { /* * Any other return value is a user exit caused by the * "return" option; this requires dedicated code to deal * with. */ throw new Exception("User return '" . $result . "' found in Textflow"); } } $p->delete_textflow($tf1); $p->delete_textflow($tf2); $p->end_document(""); $buf = $p->get_buffer(); $len = strlen($buf); header("Content-type: application/pdf"); header("Content-Length: $len"); header("Content-Disposition: inline; filename=textflow_pdfua1.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; ?>