set_option("errorpolicy=return"); $p->set_option("stringformat=utf8"); if ($p->begin_document($outfilename, "") == 0) { echo("Error: " . $p->get_errmsg()); exit(1); } $p->set_info("Creator", "PDFlib Cookbook"); $p->set_info("Title", "Starter Textflow"); /* テキストフローオブジェクトの作成し、ダミーテキストを指定する。 * オプションは2種類を交互に使用する。 */ for ($i=1; $i<=$count; $i++) { $num = $i . " "; $tf = $p->add_textflow($tf, $num, $optlist2); if ($tf == 0) { echo("Error: " . $p->get_errmsg()); exit(1); } $tf = $p->add_textflow($tf, $text, $optlist1); if ($tf == 0) { echo("Error: " . $p->get_errmsg()); exit(1); } } /* 全てのテキストが配置されるまで繰り返す。配置されるべきテキストがまだあれば、 * 新しいページを作成する。全てのページを2段組で作成する。 */ do { /* はめ込み枠の境界線を表示する場合は "showborder" を追加する */ $optlist = "verticalalign=justify linespreadlimit=120% "; $p->begin_page_ext(0, 0, "width=a4.width height=a4.height"); /* 1段目に流し込み */ $result = $p->fit_textflow($tf, $llx1, $lly1, $urx1, $ury1, $optlist); /* さらにテキストがある場合は、2段目に流し込む */ if ($result != "_stop") { $result = $p->fit_textflow($tf, $llx2, $lly2, $urx2, $ury2, $optlist); } $p->end_page_ext(""); /* "_boxfull" テキストがまだ残っているため、続けて残りのテキストを処理 * する必要がある。 * "_nextpage" 「新規段組の開始」として解釈される。 */ } while ($result == "_boxfull" || $result == "_nextpage"); /* エラーチェック */ if (!$result == "_stop") { /* "_boxempty" はめ込み枠が小さすぎて、テキストが全く入っていない場合 */ if ($result == "_boxempty") { echo("Error: Textflow box too small"); exit(1); } else { /* それ以外の戻り値は「return」オプションによるユーザー終了。 * これを扱うにはそのためのコードが必要。 */ echo("User return '" . $result . "' found in Textflow"); exit(1); } } $p->delete_textflow($tf); $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_textflow.pdf"); print $buf; } catch (PDFlibException $e) { echo("PDFlib exception occurred in starter_textflow sample:\n" . "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . $e->get_errmsg() . "\n"); exit(1); } catch (Exception $e) { echo($e); exit(1); } $p = 0; ?>