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; /* "mmm dd yyyy"の形式でフォーマットするアクションを定義し、正しいフォーマット * での日付が入力されるようにする */ $format_action = $p->create_action("JavaScript", "script={AFDate_FormatEx('mmm dd yyyy'); }"); /* フィールド種別"textfield"の "date" を生成し、"action" オプションでJavaScript * のアクションを指定する */ $optlist = "backgroundcolor={rgb 0.95 0.95 1} bordercolor={gray 0} " . "currentvalue={Oct 12 2007} maxchar=11 comb=true " . "scrollable=false tooltip={Enter a date} font=" . $monospaced_font . " fontsize=" . $fontsize . " action={format=" . $format_action . "}"; $p->create_field($llx, $lly, $llx + $width, $lly + $height, "date", "textfield", $optlist); $lly-=40; $p->setfont($font, 12); $p->fit_textline("Change the date.", $llx, $lly, ""); $p->fit_textline("After pressing \"Tab\" or \"Enter\", the date is " . "formatted as \"mmm dd yyy\".", $llx, $lly-=20, ""); $lly-=100; /* -------------------------------------------------------- * 価格を表示するためのテキストフィールドをフォーマットする * -------------------------------------------------------- * * フォントサイズをフィールドの高さに合うように調整する。そして、フィールドの * 境界線から空白を設定するためフォントサイズを小さくする(例:20%) */ $ascender = $p->info_font($monospaced_font, "ascender", "fontsize=" . $height); $descender = $p->info_font($monospaced_font, "descender", "fontsize=" . $height); $fontsize = ($ascender - $descender) * 0.8; /* "x,xxx.xx" の形式(例:"1,200.50")でフォーマットするアクションを定義し、正しい * フォーマットで数字が入力されるようにする。また、" Euro"付け加える。 */ $format_action = $p->create_action("JavaScript", "script={AFNumber_Format(2, 0, 0, 0, \" Euro\", false); }"); /* フィールド種別"textfield"の "price" を生成し、"action" オプションでJavaScript の * アクションを指定する */ $optlist = "backgroundcolor={rgb 0.95 0.95 1} bordercolor={gray 0} " . "maxchar=10 scrollable=false tooltip={Enter the price} " . "font=" . $font . " fontsize=" . $fontsize . " action={format=" . $format_action . "}"; $width=250; $p->create_field($llx, $lly, $llx + $width, $lly + $height, "price", "textfield", $optlist); $lly-=40; $p->setfont($font, 12); $p->fit_textline("Enter a price, e.g. 150.95. A maximum of 10 digits " . "is allowed to be entered.", $llx, $lly, ""); $p->fit_textline("After pressing \"Tab\" or \"Enter\", the price is " . "formatted as \"x,xxx.xx\" with the text \" Euro\" appended.", $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_input_format.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; ?>