set_option("errorpolicy=return"); $p->set_option("stringformat=utf8"); $p->set_option("searchpath={" . $searchpath . "}"); if ($p->begin_document($outfile, "") == 0) throw new Exception("Error: " . $p->get_errmsg()); $p->set_info("Creator", "PDFlib Cookbook"); $p->set_info("Title", $title); $font = $p->load_font("Helvetica", "unicode", ""); if ($font == 0) throw new Exception("Error: " . $p->get_errmsg()); $p->begin_page_ext(0, 0, "width=a4.height height=a4.width"); /* --- 画像上で、URLを開くためのリンク注釈を生成 --- */ /* 画像を配置し、範囲枠 "image_matchbox" を介して画像の寸法を * 決定する。 */ $optlist = "boxsize={50 50} fitmethod=meet matchbox={name=image_matchbox}"; $image = $p->load_image("auto", $imagefile, ""); if ($image == 0) throw new Exception("Error: " . $p->get_errmsg()); $p->fit_image($image, $x, $y, $optlist); $p->close_image($image); /* URL を開くための "URL" アクションを生成する */ $optlist = "url={" . $url . "}"; $action = $p->create_action("URI", $optlist); /* 範囲枠 "image_matchbox" を使用し, "URI" アクションによって、リンク * 注釈を生成する。長方形座標の0は範囲枠の座標に置き換えられる。 */ $optlist = "action={activate " . $action . "} linewidth=0 " . "usematchbox={image_matchbox}"; $p->create_annotation(0, 0, 0, 0, "Link", $optlist); /* --- テキスト行上で、URLを開くためのリンク注釈を生成 --- */ /* テキスト行を配置し、範囲枠 "text_matchbox" を介してテキストの寸法を * 決定する。 */ $optlist = "font=" . $font . " fontsize=20 " . "matchbox={name=text_matchbox} " . "fillcolor={rgb 0 0.6 0.6} strokecolor={rgb 0 0.6 0.6} underline"; $p->fit_textline("Go to " . $url, $x, $y-=60, $optlist); /* URL を開くための "URL" アクションを生成する */ $optlist = "url={" . $url . "}"; $action = $p->create_action("URI", $optlist); /* 範囲枠 "text_matchbox" を使用し, "URI" アクションによって、リンク * 注釈を生成する。長方形座標の0は範囲枠の座標に置き換えられる。 */ $optlist = "action={activate " . $action . "} linewidth=0 " . "usematchbox={text_matchbox}"; $p->create_annotation(0, 0, 0, 0, "Link", $optlist); /* --- テキスト行上で、他のPDFファイルへジャンプするためのリンク注釈を生成 --- */ /* テキスト行を配置し、範囲枠 "goto_matchbox" を介してテキストの寸法を * 決定する。 */ $optlist = "font=" . $font . " fontsize=20 " . "matchbox={name=goto_matchbox} " . "fillcolor={rgb 0.6 0.6 0} strokecolor={rgb 0.6 0.6 0} underline"; $p->fit_textline("Jump to file \"" . $pdffile . "\"", $x, $y-=100, $optlist); /* PDF ファイルにジャンプするための "GoToR" アクションを生成する */ $optlist = "filename={" . $pdffile . "}" . " destination {page 1 type fitwindow} newwindow"; $action = $p->create_action("GoToR", $optlist); /* 範囲枠 "text_matchbox" を使用し, "GoToR" アクションによって、リンク * 注釈を生成する。長方形座標の0は範囲枠の座標に置き換えられる。 */ $optlist = "action={activate " . $action . "} linewidth=0 " . "usematchbox={goto_matchbox}"; $p->create_annotation(0, 0, 0, 0, "Link", $optlist); /* --- テキスト行上で、JavaScriptを実行してメッセージボックスを --- * * --- 表示するリンク注釈を生成 --- */ /* テキスト行を配置し、範囲枠 "js_matchbox" を介してテキストの寸法を * 決定する。 */ $optlist = "font=" . $font . " fontsize=16 " . "matchbox={name=js_matchbox} " . "fillcolor={rgb 0.6 0 0.6} strokecolor={rgb 0.6 0 0.6} underline"; $p->fit_textline("Launch JavaScript", $x, $y-=100, $optlist); /* "JavaScript"アクションを生成し、メッセージボックスを表示する。*/ $optlist = "script={app.alert(\"JavaScript works!\")}"; $js_action = $p->create_action("JavaScript", $optlist); /* 範囲枠 "text_matchbox" を使用し, "JavaScript" アクションによって、リンク * 注釈を生成する。長方形座標の0は範囲枠の座標に置き換えられる。 */ $optlist = "action={activate " . $js_action . "} linewidth=0 " . "usematchbox={js_matchbox}"; $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=link_annotations.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; ?>