set_option("searchpath={" . $searchpath . "}"); /* load_font() の戻り値を確認する */ $p->set_option("errorpolicy=return"); /* 出力文書名を指定して、出力文書を開く */ if ($p->begin_document($outfile, "") == 0) throw new Exception("Error: " . $p->get_errmsg()); $p->set_info("Creator", "PDFlib Cookbook"); $p->set_info("Title", $title ); /* A4 横でページを作成する */ $p->begin_page_ext(0, 0, "width=a4.height height=a4.width"); /* --------------------------------------------------------------------- * オプションを指定せずテキストを出力する(改行なし) * --------------------------------------------------------------------- */ $text = "For more information about the Giant Wing Paper Plane see " . "our Web site www.kraxi-systems.com" . ".Alternatively, contact us by email " . "via questions@kraxi-systems.com" . ". You'll get all information about how to fly " . "the Giant Wing in a thunderstorm as soon as possible."; $p->fit_textline("Text without any options to avoid line breaking", 50, 430, "fontname=NotoSerif-Bold fontsize 12"); /* テキストからテキストフローを作成する */ $optlist = "fontname=NotoSerif-Regular fontsize=20 " . "leading=140%"; $tf = $p->create_textflow($text, $optlist); if ($tf == 0) throw new Exception("Error: " . $p->get_errmsg()); $result = $p->fit_textflow($tf, 50, 100, 300, 400, "fitmethod=auto showborder"); if (!$result == "_stop") { /* エラーをチェックする */ } $p->delete_textflow($tf); /* -------------------------------------------------------------- * オプションを追加して、テキストを出力する(改行あり) * -------------------------------------------------------------- */ /* テキスト行で、ウェブアドレス名などの途中で、改行を避けるために、 * "..."を使用する。 * eメールアドレス等で、特定の文字"-" や "."で改行したくない場合は、 * "..."を指定する */ $text_avoid = "For more information about the Giant Wing Paper Plane " . "see our Web site " . "www.kraxi-systems.com." . "Alternatively, contact us by email via questions@kraxi-systems.com" . ". You'll get all " . "information about how to fly the Giant Wing in a thunderstorm " . "as soon as possible."; $p->fit_textline("Text with \"charclass\" and \"avoidbreak\" options", 450, 430, "fontname=NotoSerif-Bold fontsize=12"); /* テキストからテキストフローを作成する */ $tf_avoid = $p->create_textflow($text_avoid, $optlist); if ($tf_avoid == 0) throw new Exception("Error: " . $p->get_errmsg()); $result = $p->fit_textflow($tf_avoid, 450, 100, 700, 400, "fitmethod=auto showborder"); if (!$result == "_stop") { /* Check for errors */ } $p->delete_textflow($tf_avoid); $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=avoid_linebreaking.pdf"); print $buf; } catch (PDFlibException $e) { echo("PDFlib exception occurred:\n". "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . $e->get_errmsg() . "\n"); exit(1); } catch (Throwable $e) { echo("PHP exception occurred: " . $e->getMessage() . "\n"); exit(1); } $p = 0; ?>