set_option("searchpath={" . $searchpath . "}"); /* load_font() 等でエラーが起きた場合、0を返す */ $p->set_option("errorpolicy=return"); $p->set_option("stringformat=utf8"); /* 出力PDF文書を開く */ /* "openmode=layers" 文書を開いたとき、レイヤーパネルを表示する */ if ($p->begin_document($outfile, "openmode=layers") == 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()); /* Grayscale画像をロードする */ $imageGray = $p->load_image("auto", $gray, ""); if ($imageGray == 0) throw new Exception("Error: " . $p->get_errmsg()); /* RGB 画像をロードする */ $imageRGB = $p->load_image("auto", $rgb, ""); if ($imageRGB == 0) throw new Exception("Error: " . $p->get_errmsg()); /* 使用される全てのレイヤーとそれらの関係を定義する */ /* RGBレイヤー(画像)を定義する */ $layerRGB = $p->define_layer("RGB", ""); /* Grayscaleレイヤー(画像)を定義する */ /* "initialviewstate=false" 文書を開いたとき、このレイヤーは表示しない * "initialprintstate=false" 文書を印刷するとき、このレイヤーは含めない */ $layerGray = $p->define_layer("Grayscale", "initialviewstate=false " . "initialprintstate=false"); /* Grayscale レイヤーまたは RGB レイヤーが表示される */ $p->set_layer_dependency("Radiobtn", "group={" . $layerGray . " " . $layerRGB . "}"); /* Englishレイヤー(テキスト)を定義する */ $layerEN = $p->define_layer("English", ""); /* Germanレイヤー(テキスト)を定義する */ /* "initialviewstate=false" 文書を開いたとき、このレイヤーは表示しない * "initialprintstate=false" 文書を印刷するとき、このレイヤーは含めない */ $layerDE = $p->define_layer("German", "initialviewstate=false " . "initialprintstate=false"); /* English レイヤーまたは German レイヤーが表示される */ $p->set_layer_dependency("Radiobtn", "group={" . $layerEN . " " . $layerDE . "}"); /* ページを始める */ $p->begin_page_ext(0, 0, "width=a4.width height=a4.height"); /* RGB レイヤー上に RGB 画像を配置する */ $p->begin_layer($layerRGB); $p->fit_image($imageRGB, 100, 400, "boxsize={400 300} fitmethod=meet"); /* Grayscale レイヤー上に Grayscale 画像を配置する */ $p->begin_layer($layerGray); $p->fit_image($imageGray, 100, 400, "boxsize={400 300} fitmethod=meet"); /* English レイヤー上に English 画像を配置する */ $p->begin_layer($layerEN); $p->fit_textline("This is the Nesrin image.", 100, 370, "font=" . $font . " fontsize=20"); /* German レイヤー上に German 画像を配置する */ $p->begin_layer($layerDE); $p->fit_textline("Das ist das Nesrin-Bild.", 100, 370, "font=" . $font . " fontsize=20"); $p->end_layer(); $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=starter_layer.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; ?>