/* * コンボボックス : * コンボボックスフォームフィールドを作成します。コンボボックスのリストから項目を * 選択したり、項目を変更することもできます。 * * 必要なソフトウェア : PDFlib/PDFlib+PDI/PPS 9 * 必要なデータ : 無し */ package com.pdflib.cookbook.pdflib.form_fields; import com.pdflib.pdflib; import com.pdflib.PDFlibException; public class form_combobox { public static void main (String argv[]) { /* 必要に応じてデータファイルがあるフォルダのパスを指定する */ String searchpath = "../input"; String outfile = "form_combobox.pdf"; String title = "Form Combobox"; pdflib p = null; int exitcode = 0; String optlist; int font; double width=100, height=18, llx = 100, lly = 600; try { p = new pdflib(); /* load_font() 等でエラーが起きた場合、-1を返す */ p.set_option("errorpolicy=return"); p.set_option("searchpath={" + searchpath + "}"); if (p.begin_document(outfile, "") == -1) throw new Exception("Error: " + p.get_errmsg()); p.set_info("Creator", "PDFlib Cookbook"); p.set_info("Title", title); font = p.load_font("Helvetica", "winansi", ""); if (font == -1) throw new Exception("Error: " + p.get_errmsg()); /* ページを始める */ p.begin_page_ext(0, 0, " width=a4.width height=a4.height"); /* コンボボックスのタイトルを出力する */ p.setfont(font, 14); p.fit_textline("Choose a size from the list or enter an individual " + "value:", llx, lly, ""); lly-=30; /* コンボボックスタイプのフォームフィールドを作成する * ボックスの背景をライトグレーで指定する * (backgroundcolor={gray 0.9}) * 境界線色にグレーを指定する * (bordercolor={gray 0.7}). * コンボボックスのアイテムの値を指定する(itemnamelist={0 1 2 3 4}). * コンボボックスのラベルを指定する(itemtextlist={...}). * リストアイテムの初期値を指定する(currentvalue=4). * ユーザーが項目を変更することを許可する (editable=true) */ optlist = "font=" + font + " fontsize=14 backgroundcolor={gray 0.9} " + "bordercolor={gray 0.7} itemnamelist={0 1 2 3 4} currentvalue=4 " + "itemtextlist={S M L XL XXL} editable=true"; /* リストアイテムと同じ高さでフィールドを作成する */ p.create_field(llx, lly, llx + width, lly + height, "size", "combobox", optlist); 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); } } }