set_option("searchpath={" . $searchpath . "}"); /* This means we must check return values of load_font() etc. */ $p->set_option("errorpolicy=return"); $p->set_option("stringformat=utf8"); /* 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 ); /* Create page */ $p->begin_page_ext(0, 0, "width=a4.width height=a4.height"); /* Create and fit a Textflow with two Web links. Using the inline * options "matchbox" and "matchbox end" define the two matchboxes * "kraxiweb" and "kraximail" which are used to indicate the pieces of * text on which the Web links are to be placed. Provide the matchboxes * with particular text color and decoration. */ $text = "For more information about the Giant Wing Paper Plane see the " . "Web site of Kraxi " . "Systems, Inc. or contact us by email via " . "questions@kraxi.com" . ". You'll get all " . "information about how to fly the Giant Wing in a thunderstorm " . "as soon as possible."; $optlist = "fontname=Helvetica fontsize=20 encoding=unicode leading=140%"; $tf = $p->create_textflow($text, $optlist); if ($tf == 0) throw new Exception("Error: " . $p->get_errmsg()); $result = $p->fit_textflow($tf, 100, 200, 500, 500, "fitmethod=auto"); if ($result != "_stop") { /* Check for errors */ } /* Create URI action */ $optlist = "url={http://www.kraxi.com}"; $act = $p->create_action("URI", $optlist); /* Create Link annotation on matchbox "kraxiweb" */ $optlist = "action={activate " . $act . "} linewidth=0 usematchbox={kraxiweb}"; $p->create_annotation(0, 0, 0, 0, "Link", $optlist); /* Create URI action */ $optlist = "url={mailto:questions@kraxi.com}"; $act = $p->create_action("URI", $optlist); /* Create Link annotation on matchbox "kraximail" */ $optlist = "action={activate " . $act . "} linewidth=0 usematchbox={kraximail}"; $p->create_annotation(0, 0, 0, 0, "Link", $optlist); $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=weblink_in_text.pdf"); print $buf; } catch (PDFlibException $e) { echo("PDFlib exception occurred:\n". "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . $e->get_errmsg() . "\n"); exit(1); } catch (Exception $e) { echo($e->getMessage()); exit(1); } $p = 0; ?>