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 ); /* 1ページ目 */ $p->begin_page_ext(0, 0, "width=a4.width height=a4.height"); $font = $p->load_font("Helvetica-Bold", "unicode", ""); if ($font == 0) throw new Exception("Error: " . $p->get_errmsg()); /* テキストを西向き、東向き、南向きで配置する */ $p->setfont($font, 24); $p->fit_textline("The famous rocket looper", 100, 500, "orientate=west"); $p->setfont($font, 20); $p->fit_textline("The famous rocket looper", 200, 500, "orientate=east"); $p->setfont($font, 16); $p->fit_textline("The famous rocket looper", 300, 500, "orientate=south"); /* テキストを30度回転させる */ $p->setfont($font, 16); $p->fit_textline("The famous rocket looper", 50, 350, "rotate=30"); /* テキストフローを使用し、テキストを30度回転させる */ $tf = $p->add_textflow($tf, $textflow, $optlist); if ($tf == 0) throw new Exception("Error: " . $p->get_errmsg()); $result = $p->fit_textflow($tf, 250, 50, 400, 400, "rotate=30"); if ($result != "_stop") { /* エラーかどうか、または、まだ配置すべきテキストが残っているかをチェック */ } $p->delete_textflow($tf); $p->end_page_ext(""); /* 2ページ目 */ $p->begin_page_ext(0, 0, "width=a4.width height=a4.height"); $font = $p->load_font("Helvetica-Bold", "unicode", ""); if ($font == 0) throw new Exception("Error: " . $p->get_errmsg()); /* ストロークカラーを赤に設定する */ $p->setcolor("stroke", "rgb", 1, 0, 0, 0); /* テキストフローを使用し、テキストを30度回転させる。テキストフローのオプションに、 * "showborder" を指定し、はめ込み枠の境界線を表示する */ $tf = 0; $tf = $p->add_textflow($tf, $textflow, $optlist); if ($tf == 0) throw new Exception("Error: " . $p->get_errmsg()); $result = $p->fit_textflow($tf, 150, 450, 400, 650, "showborder rotate=30"); if ($result != "_stop") { /* エラーかどうか、または、まだ配置すべきテキストが残っているかをチェック */ } $p->delete_textflow($tf); $p->fit_textline("rotate=30", 300, 500, "font=" . $font . " fontsize=14"); /* テキストフローで30度回転させ、テキストを西向きにする */ $tf = 0; $tf = $p->add_textflow($tf, $textflow, $optlist); if ($tf == 0) throw new Exception("Error: " . $p->get_errmsg()); $result = $p->fit_textflow($tf, 150, 100, 400, 300, "showborder rotate=30 orientate west"); if ($result != "_stop") { /* エラーかどうか、または、まだ配置すべきテキストが残っているかをチェック */ } $p->delete_textflow($tf); $p->fit_textline("rotate=30 orientate=west", 300, 150, "font=" . $font . " fontsize=14"); $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=frame_around_image.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; ?>