set_option("searchpath={" . $searchpath . "}"); /* load_font() 等でエラーが起きた場合、0を返す */ $p->set_option("errorpolicy=return"); $p->set_option("stringformat=utf8"); 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()); /* Start a A4 landscape page */ $p->begin_page_ext(0, 0, "width=a4.height height=a4.width"); /* ---------------------------- * 説明用のテキストを出力する * ---------------------------- */ $tf = $p->add_textflow(0, $text, "fontname=Helvetica fontsize=12 encoding=unicode leading=120%"); if ($tf == 0) throw new Exception("Error: " . $p->get_errmsg()); $p->fit_textflow($tf, 20, 20, 550, 450, ""); /* --------------------------------------------------------------- * ページを開いたときに起動する JavaScript のアクションを定義する * --------------------------------------------------------------- */ /* Acrobatのメニュー項目を JavaScript コンソールに表示するためのアクションを * 作成する */ $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 . "}"); /* ページを閉じる。 * ページを開いたときに、上記で定義したアクションを実行させるよう定義する */ $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=block_below_contents.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; ?>