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.width height=a4.height"); /* テキストを作成する。1段目と2段目に、インラインオプション * で余白を指定する。 * これは、前の段のベースラインから、行送りを150%に * 広げることを示す。(100%は、直近に設定された文字サイズに等しい) * で新しい行が開始され、先頭は初期値 (以下の * オプション リストで定義) にリセットされる。 */ $text = "Our paper planes are the ideal way of passing the time. We " . "offer revolutionary new developments of the traditional common " . "paper planes. If your lesson, conference, or lecture turn out " . "to be deadly boring, you can have a wonderful time with our " . "planes. All our models are folded from one paper sheet. They " . "are exclusively folded without using any adhesive. Several " . "models are equipped with a folded landing gear enabling a safe " . "landing on the intended location provided that you have aimed " . "well. Other models are able to fly loops or cover long " . "distances. Let them start from a vista point in the mountains " . "and see where they touch the ground." . "" . "Have a look at our new paper plane models!" . "" . "Long Distance Glider: ". "With this paper rocket you can send all your messages even when " . "sitting in a hall or in the cinema pretty near the back. " . "" . "Giant Wing: " . "An unbelievable sailplane! It is amazingly robust and can even " . "do aerobatics. But it best suited to gliding." . "" . "Cone Head Rocket: " . "This paper arrow can be thrown with big swing. We launched it " . "from the roof of a hotel. It stayed in the air a long time and " . "covered a considerable distance. " . "" . "Super Dart: " . "The super dart can fly giant loops with a radius of 4 or 5 " . "metres and cover very long distances. Its heavy cone point is " . "slightly bowed upwards to get the lift required for loops."; /* テキストを追加する */ $moretext = "German Bi-Plane: " . "Brand-new and ready for take-off. If you have lessons in the " . "history of aviation you can show your interest by letting it " . "land on your teacher's desk."; /* テキストフローを作成するためのオプションリスト。行送りは120% で指定 */ $optlist = "fontname=NotoSerif-Regular fontsize=14 " . "fillcolor={gray 0} leading=120% alignment=justify"; /* 上記で定義したオプションリストでテキストフローを作成する */ $tf = $p->create_textflow($text, $optlist); if ($tf == 0) throw new Exception("Error: " . $p->get_errmsg()); /* インラインオプションリストを使用せず、add_textflow()を使用して、 * 行送りを指定する方法を: * 新しい行を add_textflow() で追加する。一度の呼び出しで指定できるのは * "nextline" または "nextparagraph" のどちらかになるため、 * add_textflow()で別々に呼び出す必要がある。 */ $optlist = "nextline leading=80%"; $tf = $p->add_textflow($tf, "", $optlist); if ($tf == 0) throw new Exception("Error: " . $p->get_errmsg()); /* 新しい段落でテキストを追加するためのオプションリスト。他との区別のため * 色は紫色で出力する。行送りは 120% で指定する。 */ $optlist = "fontname=NotoSerif-Regular fontsize=14 " . "fillcolor={rgb 0.95 0.5 0.95} alignment=justify " . "nextparagraph leading=120%"; /* 上記で定義したオプションリストを使用して、テキストを追加する */ $tf = $p->add_textflow($tf, $moretext, $optlist); if ($tf == 0) throw new Exception("Error: " . $p->get_errmsg()); /* テキストフローを配置する */ $result = $p->fit_textflow($tf, 100, 100, 500, 700, "verticalalign=justify linespreadlimit=120% "); if (!$result == "_stop") { /* エラーチェックする */ } $p->delete_textflow($tf); $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=distance_between_paragraphs.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; ?>