set_option("searchpath={" . $searchpath . "}"); /* load_font() 等でエラーが起きた場合、0を返す */ $p->set_option("errorpolicy=return"); $p->set_option("stringformat=utf8"); $p->set_option("escapesequence=true"); if ($p->begin_document($outfile, "") == 0) throw new Exception("Error: " . $p->get_errmsg()); $p->set_info("Creator", "PDFlib Cookbook"); $p->set_info("Title", $title); /* PDFlibブロックを含む既存文書を開く */ $indoc = $p->open_pdi_document($infile, ""); if ($indoc == 0) throw new Exception("Error: " . $p->get_errmsg()); /* 既存文書の1ページ目を開く */ $inpage = $p->open_pdi_page($indoc, 1, ""); if ($inpage == 0) throw new Exception("Error: " . $p->get_errmsg()); /* 既存文書1ページ目のページサイズ(幅・高さ)を取得する */ $width = $p->pcos_get_number($indoc, "pages[0]/width"); $height = $p->pcos_get_number($indoc, "pages[0]/height"); /* 出力PDFページを既存文書のサイズで作成する */ $p->begin_page_ext($width, $height, ""); /* 既存PDFページを出力PDFページ上に配置する */ $p->fit_pdi_page($inpage, 0, 0, ""); /* "plane model"ブロックに テキスト"Long Distance Glider"を設定する */ if ($p->fill_textblock($inpage, "plane model", "Long Distance Glider", "encoding=unicode") == 0) trigger_error("Warning: " . $p->get_errmsg() . "\n"); /* "quantity"ブロックに テキスト"1"を設定する */ if ($p->fill_textblock($inpage, "quantity", "1", "encoding=unicode") == 0) trigger_error("Warning: " . $p->get_errmsg() . "\n"); /* "color"ブロック(ラジオボタンを示す)内に、円記号を指定する。この時 * fill_textblock()の第3パラメータには "&.#6C"("l")を指定する。 * ZapfDingbatsフォントで、encoding=builtinを指定した場合、以下の通り * 第3パラメータに指定することで色々な記号を取得できる。 * チェック="4"(&.#34;), 円="1"(&.#6C;), クロス="8"(&.#38;), ダイヤモ * ンド="u"(&.#75;), スクエア="n"(&.#6E;), スター="H"(&.#48;) */ $text_optlist = "fontname=ZapfDingbats encoding=builtin position=center charref=true"; if ($p->fill_textblock($inpage, "color", "&.#6C;", $text_optlist) == 0) trigger_error("Warning: " . $p->get_errmsg() . "\n"); /* "color_1"ブロック(ラジオボタンを示す)に" "(スペース)を指定する。 * これにより、ブロックの境界線のみ出力され、非選択の状態となる。 * スペースを指定しない場合、ボックスの境界線は出力されない。 */ $text_optlist = "fontname=ZapfDingbats encoding=builtin position=center"; if ($p->fill_textblock($inpage, "color_1", " ", $text_optlist) == 0) trigger_error("Warning: " . $p->get_errmsg() . "\n"); /* "perforation"ブロック(チェックボックスを示す)に、チェックマークを * 出力する。 */ $text_optlist = "fontname=ZapfDingbats fontsize=12 encoding=unicode " . "position=center "; if ($p->fill_textblock($inpage, "perforation", "\xe2\x9c\x94", $text_optlist) == 0) trigger_error("Warning: " . $p->get_errmsg() . "\n"); /* "glossy"ブロック(チェックボックスを示す)に" "(スペース)を指定する。 * これによりブロックの境界線のみ出力され、空のチェックボックスを表す。 * スペースを指定しない場合、ボックスの境界線は出力されない。 */ $text_optlist = "fontname=ZapfDingbats fontsize=12 encoding=unicode " . "position=center"; if ($p->fill_textblock($inpage, "glossy", " ", $text_optlist) == 0) trigger_error("Warning: " . $p->get_errmsg() . "\n"); $p->end_page_ext(""); $p->close_pdi_page($inpage); $p->end_document(""); $p->close_pdi_document($indoc); $buf = $p->get_buffer(); $len = strlen($buf); header("Content-type: application/pdf"); header("Content-Length: $len"); header("Content-Disposition: inline; filename=fill_converted_formfields.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; ?>