/* * しおりの階層: * いくつかのレベルにネストされたしおりを作成します。 * * タイトルページを最上位レベルのしおりとして作成し、次のページを2階層目の * しおりとして作成します。さらにそれらのページの下に、Web サイトにジャンプする * しおりを作成します。 * * 必要な製品: PDFlib/PDFlib+PDI/PPS 10 * 必要なデータ: 無し */ package com.pdflib.cookbook.pdflib.interactive; import com.pdflib.pdflib; import com.pdflib.PDFlibException; public class nested_bookmarks { public static void main (String argv[]) { /* 必要に応じてデータファイルがあるフォルダのパスを指定する */ String searchpath = "../input"; String outfile = "nested_bookmarks.pdf"; String title = "Nested Bookmarks"; pdflib p = null; int exitcode = 0; int i, numpages = 5, pagewidth=200, pageheight=100; int bm_planes, bm_plane; int x = 20, y = 50; String planes[] = { "Giant Wing", "Long Distance Glider", "Cone Head Rocket", "Super Dart", "German Bi-Plane" }; 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); /* タイトルページを作成し、最上位レベルにしおりを追加する */ p.begin_page_ext(pagewidth, pageheight, ""); p.fit_textline("Kraxi Paper Planes", x, y, "fontname=NotoSerif-Bold fontsize=14"); bm_planes = p.create_bookmark("Kraxi Paper Planes", ""); p.end_page_ext(""); /* 上記で作成した、最上位レベルのしおりの下にそれぞれしおりを * 作成する */ for (i=0; i < numpages; i++) { int action; /* ページを始める */ p.begin_page_ext(pagewidth, pageheight, ""); /* ページ上にテキストを出力する */ p.fit_textline(planes[i], x, y, "fontname=NotoSerif-Bold fontsize=14"); /* "Kraxi Paper Planes"のしおりの下に"Plane"のしおりを作成する */ bm_plane = p.create_bookmark(planes[i], "parent=" + bm_planes); /* URL を開くための"URL"アクションを生成する */ action = p.create_action("URI", "url={http://www.kraxi.com}"); /* 上記で定義したURLへ遷移するためのしおりを生成する。このしおりは * 上記で指定した"Plane"のしおりの下にあり、上から3階層目に位置している */ p.create_bookmark("Jump to the Kraxi Website", "parent=" + bm_plane + " action={activate=" + action + "}"); 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); } } }