/* * ラジオボタン : * 3つのラジオボタンフォームフィールドのグループを作成します * * フィールドグループと3つのラジオボタンを生成します * * 必要な製品 : PDFlib/PDFlib+PDI/PPS 9 * 必要なデータ : 無し */ package com.pdflib.cookbook.pdflib.form_fields; import com.pdflib.pdflib; import com.pdflib.PDFlibException; public class form_radiobutton { public static void main (String argv[]) { /* 必要に応じてデータファイルがあるフォルダのパスを指定する */ String searchpath = "../input"; String outfile = "form_radiobutton.pdf"; String title = "Form Radiobutton"; pdflib p = null; int exitcode = 0; String optlist; int font; double width=20, height=20, llx = 50, 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, 12); /* 始めに、フォームフィールドのグループ"colors"を生成する */ p.create_fieldgroup("colors", "fieldtype=radiobutton"); p.fit_textline("Choose the paper plane color:", llx, lly, ""); lly-=40; /* グレーの円を示す"radiobutton"タイプのフォームフィールドを生成する。 * (buttonstyle=circle bordercolor={gray 0.8}) * 全てのフィールドは"colors"フィールドグループに属している。 * それぞれのラジオボタンフィールド名に接頭辞"colors."を付けて関連付ける。 * 一番初めのラジオボタンをアクティブにする(currentvalue={On}) * ツールチップは常に、グループで共有する。 */ optlist = "buttonstyle=circle bordercolor={gray 0.8}"; p.create_field(llx, lly, llx + width, lly + height, "colors.standard", "radiobutton", optlist + " currentvalue={On} " + "tooltip={Select a color for the paper plane}"); /* ボタンのラベルを出力する */ p.fit_textline("Standard", llx + 30, lly, "boxsize={0 " + height + "} position={left center}"); lly-=40; p.create_field(llx, lly, llx + width, lly + height, "colors.yellow", "radiobutton", optlist); p.fit_textline("Yellow", llx + 30, lly, "boxsize={0 " + height + "} position={left center}"); lly-=40; p.create_field(llx, lly, llx + width, lly + height, "colors.blue", "radiobutton", optlist); p.fit_textline("Blue", llx + 30, lly, "boxsize={0 " + height + "} position={left center}"); lly-=40; 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); } } }