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 ); $normalfont = $p->load_font("NotoSerif-Regular", "unicode", ""); if ($normalfont == 0) throw new Exception("Error: " . $p->get_errmsg()); $boldfont = $p->load_font("NotoSerif-Bold", "unicode", ""); if ($boldfont == 0) throw new Exception("Error: " . $p->get_errmsg()); /* 画像をロードする */ $image = $p->load_image("auto", $imagefile, ""); if ($image == 0) throw new Exception("Error: " . $p->get_errmsg()); /* 出力PDFページを作成する */ $p->begin_page_ext(0, 0, "width=a4.height height=a4.width"); /* 大小のフォントの一般的なオプションを設定する */ $smallfont_opts = "font=" . $normalfont . " fontsize=" . $smallfontsize . " "; $bigfont_opts = "font=" . $boldfont . " fontsize=" . $bigfontsize . " "; /* 見出しの出力 */ $p->fit_textline("Output of fit_textline()", $x1, $y, $smallfont_opts); $p->fit_textline("Options of fit_textline()", $x2, $y, $smallfont_opts); /* * ------------------------------------------------------ * デフォルトの shadow オプションによるテキストの出力 * ------------------------------------------------------ */ $shadow_opts = "shadow={} "; $p->fit_textline($text, $x1, $y -= $yoff, $bigfont_opts . $shadow_opts); /* Output a description of the shadow options */ $p->fit_textline($shadow_opts, $x2, $y + $bigfontsize / 4, $smallfont_opts); /* * ------------------------------------------------------------- * 色々な shadow オプション (デフォルト値は {5% -5%})による * テキストの出力 * ------------------------------------------------------------- */ $shadow_opts = "shadow={offset={10% 8%}} "; $p->fit_textline($text, $x1, $y -= $yoff, $bigfont_opts . $shadow_opts); /* shadow オプションの説明用テキスト */ $p->fit_textline($shadow_opts, $x2, $y + $bigfontsize / 4, $smallfont_opts); /* デフォルトの shadow オプション値による、テキストの出力 */ $shadow_opts = "shadow={offset={-10% 8%}} "; $p->fit_textline($text, $x1, $y -= $yoff, $bigfont_opts . $shadow_opts); /* shadow オプションの説明用テキスト */ $p->fit_textline($shadow_opts, $x2, $y + $bigfontsize / 4, $smallfont_opts); /* デフォルトの shadow オプション値による、テキストの出力 */ $shadow_opts = "shadow={offset={-10% -8%}} "; $p->fit_textline($text, $x1, $y -= $yoff, $bigfont_opts . $shadow_opts); /* shadow オプションの説明用テキスト */ $p->fit_textline($shadow_opts, $x2, $y + $bigfontsize / 4, $smallfont_opts); /* * ------------------------------------------- * 色々な色での影付きテキストの出力 * ------------------------------------------- */ $shadow_opts = "shadow={fillcolor={rgb 0.28 0.81 0.8} offset={10% -10%}} "; $color_opts = "fillcolor={rgb 0 0.5 0.52}"; $p->fit_textline($text, $x1, $y -= $yoff, $bigfont_opts . $shadow_opts . $color_opts); /* shadow オプションにより出力 */ $p->fit_textline($shadow_opts, $x2, $y + $bigfontsize / 4, $smallfont_opts); /* * カレントグラフィックステータスを保存する。 * save/restore は必ずしも必要ではないが、後で保存しておいた * グラフィックステータスに復帰する場合、役に立つ */ $p->save(); /* 背景画像を出力する */ $p->fit_image($image, $x1, 50, "boxsize={170 170} fitmethod=meet"); /* * create_gstate()のオプション値"opacityfill"に0.5(透明度50%)を * 指定する */ $gstate = $p->create_gstate("opacityfill=.5"); /* 上記で指定した透明度で、白の影付きテキストを表示する */ $base_shadow_opts = "shadow={fillcolor={rgb 0.87 0.72 0.52} " . "offset={8% -8%}} gstate="; $shadow_opts = $base_shadow_opts . $gstate; $color_opts = " fillcolor={rgb 1 1 1}"; $p->fit_textline("the", $x1, 185, $bigfont_opts . $shadow_opts . $color_opts); $p->fit_textline("faces", $x1, 145, $bigfont_opts . $shadow_opts . $color_opts); $p->fit_textline("of", $x1, 105, $bigfont_opts . $shadow_opts . $color_opts); $p->fit_textline("Bayon", $x1, 65, $bigfont_opts . $shadow_opts . $color_opts); /* 保存したグラフィックステータスに復帰する */ $p->restore(); /* shadow オプションにより出力 */ $p->fit_textline($base_shadow_opts ."", $x2, 145, $smallfont_opts); $p->fit_textline("(gstate is created with \"opacityfill=.5\")", $x2, 115, $smallfont_opts); $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=shadow_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; ?>