/* * 段落の間隔 : * 段落の間隔をコントロールする * * 文字の多いページでは、段落と段落の間は、段落内の行の間隔より大きくした方が見やすくなります。 * add/create_textflow 関数の nextline、leading、nextparagraph オプションを使うと、 * 適切な値により余分な空白行を挿入することができます。 * * 必要な製品: PDFlib/PDFlib+PDI/PPS 10 * 必要なデータ: 無し */ package com.pdflib.cookbook.pdflib.textflow; import com.pdflib.pdflib; import com.pdflib.PDFlibException; public class distance_between_paragraphs { public static void main (String argv[]) { /* 必要に応じてデータファイルがあるフォルダのパスを指定する */ String searchpath = "../input"; String outfile = "distance_between_paragraphs.pdf"; String title = "Distance between Paragraphs"; pdflib p = null; int exitcode = 0; int tf = -1; String result, optlist; try { p = new pdflib(); p.set_option("searchpath={" + searchpath + "}"); /* load_font()等の戻り値を確認する */ p.set_option("errorpolicy=return"); /* 出力文書名を指定して、出力文書を開く */ if (p.begin_document(outfile, "") == -1) 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%は、直近に設定された文字サイズに等しい) * で新しい行が開始され、先頭は初期値 (以下の * オプション リストで定義) にリセットされる。 */ final String 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."; /* テキストを追加する */ String 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 == -1) 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 == -1) 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 == -1) throw new Exception("Error: " + p.get_errmsg()); /* テキストフローを配置する */ result = p.fit_textflow(tf, 100, 100, 500, 700, "verticalalign=justify linespreadlimit=120% "); if (!result.equals("_stop")) { /* エラーチェックする */ } p.delete_textflow(tf); p.end_page_ext(""); p.end_document(""); } catch (PDFlibException e){ System.err.println("PDFlib exception occurred:"); System.err.println("[" + e.get_errnum() + "] " + e.get_apiname() + ": " + e.get_errmsg()); exitcode = 1; } catch (Exception e) { System.err.println(e); exitcode = 1; } finally { if (p != null) { p.delete(); } System.exit(exitcode); } } }