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 bulleted list * ---------------------- */ $p->begin_page_ext(0, 0, "width=a4.width height=a4.height"); /* Create the Textflow. First, add a heading */ $tf = $p->add_textflow($tf, "Page 1: Bulleted list\n\n\n", $head_optlist); if ($tf == 0) throw new Exception("Error: " . $p->get_errmsg()); /* Add list bullets and items. For the list bullets, use "leftindent=0" * and for the items, use "leftindent=22" to indent the item text. * For list bullets, use the "charref" option to enable PDFlib to * resolve "•" as for the bullet in the Symbol font. */ $num_optlist = "fontname=Symbol fontsize=12 escapesequence " . "fillcolor={cmyk 1 0.5 0.2 0} leftindent=0 charref=true"; $item_optlist = "fontname=NotoSerif-Regular fontsize=12 " . "fillcolor={gray 0} alignment=justify leading=140% leftindent=22 "; for ($i = 0; $i < 4; $i++) { $tf = $p->add_textflow($tf, "•", $num_optlist); if ($tf == 0) throw new Exception("Error: " . $p->get_errmsg()); $tf = $p->add_textflow($tf, $items[$i] . "\n\n", $item_optlist); if ($tf == 0) throw new Exception("Error: " . $p->get_errmsg()); } /* Place the Textflow */ $result = $p->fit_textflow($tf, $llx, $lly, $urx, $ury, ""); if (!$result == "_stop") { /* Check for further action */ } $p->delete_textflow($tf); $p->end_page_ext(""); /* ---------------------- * Create a numbered list * ---------------------- */ $p->begin_page_ext(0, 0, "width=a4.width height=a4.height"); /* Create the Textflow. First, add a heading */ $tf = 0; $tf = $p->add_textflow($tf, "Page 2: Numbered list\n\n\n", $head_optlist); if ($tf == 0) throw new Exception("Error: " . $p->get_errmsg()); /* Add list numbers and list items. For the list numbers, use * "leftindent=0" and for the items, use "leftindent=22" to indent the * item text. */ $num_optlist = "fontname=NotoSerif-Bold fontsize=12 " . "fillcolor={cmyk 1 0.5 0.2 0} leftindent=0"; $item_optlist = "fontname=NotoSerif-Regular fontsize=12 " . "fillcolor={gray 0} alignment=justify leading=140% leftindent=22"; for ($i = 0; $i < 4; $i++) { $tf = $p->add_textflow($tf, $i + 1, $num_optlist); if ($tf == 0) throw new Exception("Error: " . $p->get_errmsg()); $tf = $p->add_textflow($tf, $items[$i] . "\n\n", $item_optlist); if ($tf == 0) throw new Exception("Error: " . $p->get_errmsg()); } /* Place the Textflow */ $result = $p->fit_textflow($tf, $llx, $lly, $urx, $ury, ""); if (!$result == "_stop") { /* Check for further action */ } $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=bulleted_list.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; ?>