/* * チェックボックス : * 4つのチェックボックスフォームフィールドを作成します。 * * "paper plane"の注文で特典を選択するため、4つのチェックボックスを定義します。 * * 必要な製品 : PDFlib/PDFlib+PDI/PPS 9 * 必要なデータ : 無し */ package com.pdflib.cookbook.pdflib.form_fields; import com.pdflib.pdflib; import com.pdflib.PDFlibException; public class form_checkbox { public static void main (String argv[]) { /* 必要に応じてデータファイルがあるフォルダのパスを指定する */ String searchpath = "../input"; String outfile = "form_checkbox.pdf"; String title = "Form Checkbox"; pdflib p = null; int exitcode = 0; String optlist; int font; double width=15, height=15, 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); /* チェックボックスのためのテキストのタイトルを出力する */ p.fit_textline("Choose paper plane extras:", llx, lly, ""); lly-=40; /* チェックボックスのフォームフィールドを作成する。 * チェックボックス内は青のバツ印で表示する * (buttonstyle=cross fillcolor={rgb 0.25 0 0.95}) * 背景はライトブルー(backgroundcolor={rgb 0.95 0.95 1}) * 境界線は黒色 (bordercolor={gray 0}). * ツールヒントを提供する. * 初めのチェックボックスを有効にする (currentvalue={On}). */ optlist = "buttonstyle=cross bordercolor={gray 0} " + "backgroundcolor={rgb 0.95 0.95 1} fillcolor={rgb 0.25 0 0.95}"; p.create_field(llx, lly, llx + width, lly + height, "paper", "checkbox", optlist + " currentvalue={On}"); /* チェックボックスのラベルを出力する */ p.fit_textline("Glossy paper", llx + 30, lly, "boxsize={0 " + height + "} position={left center}"); lly-=30; p.create_field(llx, lly, llx + width, lly + height, "color", "checkbox", optlist); p.fit_textline("Rainbow colors", llx + 30, lly, "boxsize={0 " + height + "} position={left center}"); lly-=30; p.create_field(llx, lly, llx + width, lly + height, "perforation", "checkbox", optlist); p.fit_textline("Perforation", llx + 30, lly, "boxsize={0 " + height + "} position={left center}"); lly-=30; p.create_field(llx, lly, llx + width, lly + height, "stability", "checkbox", optlist); p.fit_textline("High stability", llx + 30, lly, "boxsize={0 " + height + "} position={left center}"); 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); } } }