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 the title page with a top-level bookmark */ $p->begin_page_ext($pagewidth, $pageheight, ""); $p->fit_textline("Kraxi Paper Planes", $x, $y, "fontname=NotoSerif-Bold fontsize=14"); $bm_planes = $p->create_bookmark("Kraxi Paper Planes", ""); $p->end_page_ext(""); /* Create further pages with a bookmark each which is nested below the * top-level bookmark created above */ for ($i=0; $i < $numpages; $i++) { /* Start page */ $p->begin_page_ext($pagewidth, $pageheight, ""); /* Output some text on the page */ $p->fit_textline($planes[$i], $x, $y, "fontname=NotoSerif-Bold fontsize=14"); /* Create a "Plane" bookmark on the page which is nested under the * "Kraxi Paper Planes" bookmark */ $bm_plane = $p->create_bookmark($planes[$i], "parent=" . $bm_planes); /* Create a "URI" action for opening a URL */ $action = $p->create_action("URI", "url={http://www.kraxi.com}"); /* Create a bookmark which jumps to be URL defined above. This * bookmark is nested on level three under the "Plane" bookmark * created above. */ $p->create_bookmark("Jump to the Kraxi Website", "parent=" . $bm_plane . " action={activate=" . $action . "}"); $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=nested_bookmarks.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; ?>