set_option("searchpath={" . $searchpath . "}"); $p->set_option("stringformat=utf8"); /* load_font() 等でエラーが起きた場合、0を返す */ $p->set_option("errorpolicy=return"); /* レイヤーパネルを表示してドキュメントを開く */ 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", "winansi", ""); if ($font == 0) { throw new Exception("Error: " . $p->get_errmsg()); } /* ページを始める */ $p->begin_page_ext(0, 0, "width=a4.width height=a4.height"); /* ------------------------------------------------------------------ * "English"レイヤーを定義し、英語のテキストだけでなく、英語リストの * アイテムを表示する。 * "combobox"タイプのフォームフィールドを配置する。 * ------------------------------------------------------------------ */ $layerEN = $p->define_layer("English", ""); $p->begin_layer($layerEN); /* コンボボックスのタイトルを英語で出力する */ $p->setfont($font, 12); $p->fit_textline("Choose a color from the list or enter an individual " . "color:", $llx, $lly, ""); $lly-=30; /* 英語のリストアイテムを持つコンボボックスタイプの"color"フォームフィー * ルドを作成する。 * もう片方のリストアイテムと高さを揃える。 */ $optlist = "font=" . $font . " fontsize=14 backgroundcolor={gray 0.9} " . "bordercolor={gray 0.7} itemnamelist={0 1 2 3 4} currentvalue=4 " . "itemtextlist={yellow green blue red white} editable=true layer=" . $layerEN; $p->create_field($llx, $lly, $llx + $width, $lly + $height, "color", "combobox", $optlist); /* ----------------------------------------------------------------- * "German"レイヤーを定義し、ドイツ語のテキストだけでなく、ドイツ語 * リストのアイテムを表示する。 * "combobox"タイプのフォームフィールドを配置する。 * ----------------------------------------------------------------- */ $layerDE = $p->define_layer("German", "initialviewstate=false " . "initialprintstate=false"); $p->begin_layer($layerDE); $lly=600; $p->fit_textline("W\xc3\xa4hlen Sie eine Farbe aus der Liste oder geben Sie " . "eine eigene Farbe ein:", $llx, $lly, ""); $lly-=30; /* ドイツ語のリストアイテムを持つ"combobox"タイプの"farbe"フォーム * フィールドを作成する。 * もう片方のリストアイテムと高さを揃える。 */ $optlist = "font=" . $font . " fontsize=14 backgroundcolor={gray 0.9} " . "bordercolor={gray 0.7} itemnamelist={0 1 2 3 4} currentvalue=4 " . "itemtextlist={gelb grun blau rot weis} editable=true layer=" . $layerDE; $p->create_field($llx, $lly, $llx + $width, $lly + $height, "farbe", "combobox", $optlist); /* "English" と "German"のレイヤーが表示される */ $p->set_layer_dependency("Radiobtn", "group={" . $layerEN . " " . $layerDE . "}"); /* English レイヤーを表示する "SetOCGState" アクションを作成する。 * レイヤーが表示されている場合、German レイヤーを隠す必要はない。 */ $en_act = $p->create_action("SetOCGState", "layerstate={on " . $layerEN . "}"); /* German レイヤーを表示する "SetOCGState" アクションを作成する。 * レイヤーが表示されている場合、English レイヤーを隠す必要はない。 */ $de_act = $p->create_action("SetOCGState", "layerstate={on " . $layerDE . "}"); /* "english" and "german" フォームフィールドを "pushbutton"タイプで * 作成する。 * ユーザーがフォームフィールド内でマウスボタンを離したとき、他のレイ * ヤーのスイッチ上に定義されたアクションを使用する * (action={up }) */ $lly = 680; $optlist = "bordercolor={rgb 0.25 0 0.95} backgroundcolor={rgb 0.95 0.95 1} " . "fillcolor={rgb 0.25 0 0.95} font=" . $font . " fontsize=14"; $p->create_field($llx, $lly, $llx + $width, $lly + $height, "english", "pushbutton", $optlist . " caption={English} action={up " . $en_act . "}"); $llx+=150; $p->create_field($llx, $lly, $llx + $width, $lly + $height, "german", "pushbutton", $optlist . " caption={Deutsch} action={up " . $de_act . "}"); /* 全てのレイヤーを終了する */ $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=form_and_layers.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; ?>