Introduction" . "\t7" . "Chapter 1" . "\t25" . "Chapter 2" . "\t107" . "Chapter 3" . "\t219" . "Appendix\t240"; try { $p = new pdflib(); $p->set_option("searchpath={" . $searchpath . "}"); /* 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); /* Create a Textflow */ $tf = $p->create_textflow($text, $optlist); if ($tf == 0) throw new Exception("Error: " . $p->get_errmsg()); /* Loop until all of the text is placed; create new pages * as long as more text needs to be placed. */ do { $p->begin_page_ext(0, 0, "width=a4.width height=a4.height"); /* Place a text line with a title */ $p->fit_textline("Table of Contents", 50, 740, "fontname=NotoSerif-Bold fontsize=18"); /* Place the Textflow with the table of contents */ $result = $p->fit_textflow($tf, 50, 600, 500, 700, ""); $p->end_page_ext(""); /* "_boxfull" means we must continue because there is more text; * "_nextpage" is interpreted as "start new column" */ } while ($result == "_boxfull" || $result == "_nextpage"); /* 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($tf); $p->end_document(""); $buf = $p->get_buffer(); $len = strlen($buf); header("Content-type: application/pdf"); header("Content-Length: $len"); header("Content-Disposition: inline; filename=dot_leaders_with_tabs.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; ?>