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); /* Start a A4 landscape page */ $p->begin_page_ext(0, 0, "width=a4.height height=a4.width"); /* ---------------------------- * Output some descriptive text * ---------------------------- */ $tf = $p->add_textflow(0, $text, "fontname=NotoSerif-Regular fontsize=12 leading=120%"); if ($tf == 0) throw new Exception("Error: " . $p->get_errmsg()); $p->fit_textflow($tf, 20, 20, 550, 450, ""); /* --------------------------------------------------------------- * Define JavaScript actions to be triggered upon opening the page * --------------------------------------------------------------- */ /* Create an action of type "Named" to execute the Acrobat menu command * for opening the JavaScript console */ $console = $p->create_action("Named", "menuname={EScript:JSDebugger}"); /* Create a JavaScript action to show the names of all Acrobat menu * items in the JavaScript console */ $menuitems = $p->create_action("JavaScript", "script {" . $list_menu_names . "}"); /* Close the page. For the page trigger "open", supply the JavaScript * page actions defined above. */ $optlist = "action {open={" . $console . " " . $menuitems . "}}"; $p->end_page_ext($optlist); $p->end_document(""); $buf = $p->get_buffer(); $len = strlen($buf); header("Content-type: application/pdf"); header("Content-Length: $len"); header("Content-Disposition: inline; filename=acrobat_menu_items.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; ?>