/* * レイヤー : * いくつかのレイヤーを定義し、それぞれの内部で定義したイメージやテキストを出力します。 * * RGB、グレースケールのための2つのレイヤーを定義し、英語、ドイツ語のイメージキャプ * ションのための2つのレイヤーを定義します。それぞれのレイヤーにイメージ、テキストを * 出力して、RGB イメージと英語キャプションが表示される文書をオープンします。 * * 必要な製品 : PDFlib/PDFlib+PDI/PPS 9 * 必要なデータ : グレースケールイメージファイル、RGB イメージファイル */ package com.pdflib.cookbook.pdflib.graphics; import com.pdflib.pdflib; import com.pdflib.PDFlibException; public class starter_layer { public static void main (String argv[]) { /* 必要に応じてデータファイルがあるフォルダのパスを指定する */ String searchpath = "../input"; String outfile = "starter_layer.pdf"; String title = "Starter Layer"; pdflib p = null; String rgb = "nesrin.jpg"; String gray = "nesrin_gray.jpg"; int font, imageRGB, imageGray, layerRGB, layerGray, layerEN, layerDE; int exitcode = 0; try { p = new pdflib(); p.set_option("searchpath={" + searchpath + "}"); /* load_font() 等でエラーが起きた場合、-1を返す */ p.set_option("errorpolicy=return"); /* 出力PDF文書を開く */ /* "openmode=layers" 文書を開いたとき、レイヤーパネルを表示する */ if (p.begin_document(outfile, "openmode=layers") == -1) throw new Exception("Error: " + p.get_errmsg()); p.set_info("Creator", "PDFlib Cookbook"); p.set_info("Title", title); /* フォントをロードする */ font = p.load_font("Helvetica", "unicode", ""); if (font == -1) throw new Exception("Error: " + p.get_errmsg()); /* Grayscale画像をロードする */ imageGray = p.load_image("auto", gray, ""); if (imageGray == -1) throw new Exception("Error: " + p.get_errmsg()); /* RGB 画像をロードする */ imageRGB = p.load_image("auto", rgb, ""); if (imageRGB == -1) throw new Exception("Error: " + p.get_errmsg()); /* 使用される全てのレイヤーとそれらの関係を定義する */ /* RGBレイヤー(画像)を定義する */ layerRGB = p.define_layer("RGB", ""); /* Grayscaleレイヤー(画像)を定義する */ /* "initialviewstate=false" 文書を開いたとき、このレイヤーは表示しない * "initialprintstate=false" 文書を印刷するとき、このレイヤーは含めない */ layerGray = p.define_layer("Grayscale", "initialviewstate=false " + "initialprintstate=false"); /* Grayscale レイヤーまたは RGB レイヤーが表示される */ p.set_layer_dependency("Radiobtn", "group={" + layerGray + " " + layerRGB + "}"); /* Englishレイヤー(テキスト)を定義する */ layerEN = p.define_layer("English", ""); /* Germanレイヤー(テキスト)を定義する */ /* "initialviewstate=false" 文書を開いたとき、このレイヤーは表示しない * "initialprintstate=false" 文書を印刷するとき、このレイヤーは含めない */ layerDE = p.define_layer("German", "initialviewstate=false " + "initialprintstate=false"); /* English レイヤーまたは German レイヤーが表示される */ p.set_layer_dependency("Radiobtn", "group={" + layerEN + " " + layerDE + "}"); /* ページを始める */ p.begin_page_ext(0, 0, "width=a4.width height=a4.height"); /* RGB レイヤー上に RGB 画像を配置する */ p.begin_layer(layerRGB); p.fit_image(imageRGB, 100, 400, "boxsize={400 300} fitmethod=meet"); /* Grayscale レイヤー上に Grayscale 画像を配置する */ p.begin_layer(layerGray); p.fit_image(imageGray, 100, 400, "boxsize={400 300} fitmethod=meet"); /* English レイヤー上に English 画像を配置する */ p.begin_layer(layerEN); p.fit_textline("This is the Nesrin image.", 100, 370, "font=" + font + " fontsize=20"); /* German レイヤー上に German 画像を配置する */ p.begin_layer(layerDE); p.fit_textline("Das ist das Nesrin-Bild.", 100, 370, "font=" + font + " fontsize=20"); p.end_layer(); 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); } } }