/*
* 改行位置の指定 :
* テキストフロー内で、改行位置を指定する
*
* 対象製品 : PDFlib/PDFlib+PDI/PPS 9
* 必要なデータ : 無し
*/
package com.pdflib.cookbook.pdflib.textflow;
import com.pdflib.pdflib;
import com.pdflib.PDFlibException;
public class avoid_linebreaking
{
public static void main (String argv[])
{
/* 必要に応じてデータファイルがあるフォルダのパスを指定する */
String searchpath = "../input";
String outfile = "avoid_linebreaking.pdf";
String title = "Avoid Line Breaking";
pdflib p = null;
int exitcode = 0;
int tf = -1, tf_avoid = -1, font;
String result, optlist, text, text_avoid;
try {
p = new pdflib();
p.set_option("searchpath={" + searchpath + "}");
/* load_font() 等でエラーが起きた場合、0を返す */
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.height height=a4.width");
/* フォントをロードする */
font = p.load_font("Helvetica-Bold", "unicode", "");
if (font == -1)
throw new Exception("Error: " + p.get_errmsg());
p.setfont(font, 12);
/* ---------------------------------------------------------------------
* オプションを指定せずテキストを出力する(改行なし)
* ---------------------------------------------------------------------
*/
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, "");
/* テキストからテキストフローを作成する */
optlist = "fontname=Helvetica fontsize=20 encoding=unicode " +
"leading=140%";
tf = p.create_textflow(text, optlist);
if (tf == -1)
throw new Exception("Error: " + p.get_errmsg());
result = p.fit_textflow(tf, 50, 100, 300, 400,
"fitmethod=auto showborder");
if (!result.equals("_stop"))
{
/* エラーをチェックする */
}
p.delete_textflow(tf);
/* --------------------------------------------------------------
* オプションを追加して、テキストを出力する(改行あり)
* --------------------------------------------------------------
*/
/* テキスト行で、ウェブアドレス名などの途中で、改行を避けるために、
* "..."を使用する。
* eメールアドレス等で、特定の文字"-" や "."で改行したくない場合は、
* "charclass={letter {- .}}>..."を指定する
*/
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, "");
/* テキストからテキストフローを作成 */
tf_avoid = p.create_textflow(text_avoid, optlist);
if (tf_avoid == -1)
throw new Exception("Error: " + p.get_errmsg());
result = p.fit_textflow(tf_avoid, 450, 100, 700, 400,
"fitmethod=auto showborder");
if (!result.equals("_stop"))
{
/* エラーをチェックする */
}
p.delete_textflow(tf_avoid);
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);
}
}
}