java,v 1.16 2007/10/30 16:16:33 katja Exp $ * * 簡単なスタンプ : * 対角線上にページを横切るスタンプを作成するサンプルプログラムです。 * * テキストフローの背景にスタンプのようなテキストアウトラインを配置します。 * また、イメージ上に不透明なスタンプのようなテキスト行を配置します。 * * 必要な製品 : PDFlib/PDFlib+PDI/PPS 9 * 必要なデータ : 無し */ /* 必要に応じてデータファイルがあるフォルダのパスを指定する */ $searchpath = dirname(__FILE__,3)."/input"; $outfile = ""; $title = "Simple Stamp"; $imagefile = "nesrin.jpg"; $tf = 0; $llx=50; $lly=50; $optlist = "fontname=Helvetica fontsize=24 encoding=unicode leading=120% charref"; $textflow = "To fold the famous rocket looper proceed as follows:\n" . "Take a DIN A4 sheet.\nFold it lenghtwise in the middle.\nThen, fold " . "the upper corners down.\nFold the long sides inwards that the " . "points A and B meet on the central fold.\nFold the points C and D " . "that the upper corners meet with the central fold as well." . "\nFold the plane in the middle. Fold the wings down that they close " . "with the lower border of the plane."; try { $p = new pdflib(); $p->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()); /* スタンプのようなテキストアウトラインを配置する。 * スタンプは左上隅から右下隅への対角線上に配置される(stamp=ul2lr) */ $p->fit_textline("The Famous Rocket Looper", $llx, $lly, "font=" . $font . " strokecolor={rgb 1 0 0} textrendering=1 boxsize={500 750} " . "strokecolor={rgb 0.5 0 1} stamp=ul2lr"); /* スタンプの上にテキストフローを配置する */ $tf = $p->add_textflow($tf, $textflow, $optlist); if ($tf == 0) throw new Exception("Error: " . $p->get_errmsg()); $result = $p->fit_textflow($tf, 100, 100, 400, 700, ""); if ($result != "_stop") { /* エラーかどうか、または、まだ配置すべきテキストが残っているかをチェック */ } $p->end_page_ext(""); /* 2ページ目 */ $p->begin_page_ext(350, 220, ""); /* 背景に使用する画像をロードする */ $image = $p->load_image("auto", $imagefile, ""); if ($image == 0) throw new Exception("Error: " . $p->get_errmsg()); $p->fit_image($image, 0, 0, "scale=0.5"); /* カレントグラフィックステータスを保存する */ $p->save(); /* スタンプを透明に表示するため、グラフィックステータスに透明度を設定する */ $gstate = $p->create_gstate("opacityfill=0.5"); $p->set_gstate($gstate); /* スタンプのようなテキストアウトラインを配置する。 * スタンプは右上隅から左下隅への対角線上に配置(stamp=ll2ur)され、上記で設定したとおり、 * 透明な白で出力される。 */ $p->fit_textline("Our Test Image", 30, 10, "font=" . $font . " fillcolor={rgb 1 1 1} boxsize={300 200} fontsize=1 stamp=ll2ur"); $p->restore(); $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=simple_stamp.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; ?>