set_option("errorpolicy=return"); $p->set_option("stringformat=utf8"); $p->set_option("searchpath={" . $searchpath . "}"); if ($p->begin_document($outfile, "") == 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()); $monospaced_font = $p->load_font("Courier", "winansi", ""); if ($monospaced_font == 0) throw new Exception("Error: " . $p->get_errmsg()); /* ページを始める */ $p->begin_page_ext(0, 0, " width=a4.width height=a4.height"); /* フォントの高さに合うようにフォントサイズを調整する:フィールドの 高さと * 等しい仮定的なフォントサイズのアセンダ値、ディセンダ値(通常は非奨励) * を取得し、アセンダと(明確な)ディセンダーの合計した値をフォントサイズと * して使用する。 * そして、フィールド境界から若干の空のスペースを残すために、20%フォントサ * イズを小さくする。 */ $ascender = $p->info_font($monospaced_font, "ascender", "fontsize=" . $height); $descender = $p->info_font($monospaced_font, "descender", "fontsize=" . $height); $fontsize = ($ascender - $descender) * 0.8; /* フォームフィールド種別"textfield"の"date" フィールドを生成し、背景色にライト * ブルー、境界線に黒を指定する。 * 日付を初期表示する(currentvalue={Sep 10 2007}) * 入力できる最大文字数を11文字に指定する(maxchar=11) * テキストがフィールドを満たしたとき、それ以上は入力を受け付けないようにする * (scrollable=false) * フィールドはキャラクタごとに等間隔に、サブフィールドに分割される(comb=true) * ツールチップは、ユーザーがフィールド上にカーソルを移動したとき表示する * (tooltip={Enter a date}) */ $optlist = "backgroundcolor={rgb 0.95 0.95 1} bordercolor={gray 0} " . "currentvalue={Sep 10 2007} maxchar=11 scrollable=false comb=true " . "tooltip={Enter a date} font=" . $monospaced_font . " fontsize=" . $fontsize; $p->create_field($llx, $lly, $llx + $width, $lly + $height, "date", "textfield", $optlist); $lly-=40; $p->setfont($font, 12); $p->fit_textline("Form text field with an initial value set. The " . "characters are placed in equidistant subfields.", $llx, $lly, ""); $p->fit_textline("A maximum of 11 characters is allowed. The text is " . "not allowed to scroll out of the window.", $llx, $lly-=20, ""); $p->fit_textline("A tooltip is displayed when the mouse moves over the " . "field.", $llx, $lly-=20, ""); $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_textfield_layout.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; ?>