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 ); /* Start Page */ $p->begin_page_ext(0, 0, "width=a4.width height=a4.height"); /* ----------------- * Table of contents * ----------------- */ /* Output a heading */ $p->fit_textline("Table of contents", $x, $y, $headopts); /* Option list for the text entry. The text is placed in a box with a * width of 400 using boxsize={400 30}. The "leader" option is used to * define leaders to be used. The "alignment" suboption specifies the * alignment between text, leaders, and box. The default leader * character is ".". Use the "text" suboption to define one or more * other characters to be used as leaders. */ $textopts = "fontname=NotoSerif-Regular fontsize=14 " . "boxsize={" . $bw . " 30} leader={alignment=right}"; /* Option list for the page number */ $numopts = "fontname=NotoSerif-Bold fontsize=14 " . "fillcolor={cmyk 1 0.5 0.2 0}"; for ($i = 0; $i < 4; $i++) { /* Place the text line */ $p->fit_textline($items[$i][0], $x, $y-=$yoff, $textopts); /* To the right of the text box place the page number with a * distance of 10 */ $p->fit_textline($items[$i][1], $x+$bw+10, $y, $numopts); } /* ------------------------------------------------ * Table of contents with the numbers right-aligned * ------------------------------------------------ */ /* Output a heading */ $p->fit_textline("Table of contents with the numbers right-aligned", $x, $y-=2*$yoff, $headopts); /* In this case, the number is placed right-aligned with * "position={right bottom}" in a box with a width of 20 using * "boxsize={20 30}". */ $numopts = "fontname=NotoSerif-Bold fontsize=14 " . "boxsize={20 30} position={right bottom} " . "fillcolor={cmyk 1 0.5 0.2 0}"; for ($i = 0; $i < 4; $i++) { /* Place the text line */ $p->fit_textline($items[$i][0], $x, $y-=$yoff, $textopts); /* To the right of the text box place the page number right-aligned * into a box with a width of 20 */ $p->fit_textline($items[$i][1], $x+$bw, $y, $numopts); } $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=leaders_in_textline.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; ?>