1 import org.faceless.pdf2.*; 2 import java.io.*; 3 import java.awt.Color ; 4 5 public class FormCreation 17 { 18 public static void main(String [] args) 19 throws IOException 20 { 21 PDF pdf = new PDF(); 22 PDFPage page = pdf.newPage(PDF.PAGESIZE_A4); 23 24 PDFStyle label = new PDFStyle(); 28 label.setFillColor(Color.black); 29 label.setFont(new StandardFont(StandardFont.HELVETICA), 11); 30 page.setStyle(label); 31 page.drawText("Name:", 100, 708); 32 page.drawText("Year of birth:", 100, 668); 33 page.drawText("Address:", 330, 708); 34 page.drawText("Rating:", 100, 628); 35 page.drawText("1", 155, 628); 36 page.drawText("5", 255, 628); 37 page.drawText("Yes, send me spam!:", 330, 628); 38 39 40 Form form = pdf.getForm(); 46 PDFStyle background = new PDFStyle(); 47 background.setFillColor(new Color (240,240,255)); 48 background.setLineColor(Color.blue); 49 background.setFormStyle(PDFStyle.FORMSTYLE_BEVEL); 50 form.setBackgroundStyle(background); 51 52 FormText name = new FormText(page, 170, 700, 300, 720); 55 form.addElement("Name", name); 56 57 FormText address = new FormText(page, 400, 660, 550, 720); 60 address.setType(FormText.TYPE_MULTILINE); 61 form.addElement("Address", address); 62 63 FormChoice month = new FormChoice( FormChoice.TYPE_SCROLLABLE, page , 170, 660, 230, 680); 66 month.getOptions().put("Jan",null); 67 month.getOptions().put("Feb",null); 68 month.getOptions().put("Mar",null); 69 month.getOptions().put("Apr",null); 70 month.getOptions().put("May",null); 71 month.getOptions().put("Jun",null); 72 month.getOptions().put("Jul",null); 73 month.getOptions().put("Aug",null); 74 month.getOptions().put("Sep",null); 75 month.getOptions().put("Oct",null); 76 month.getOptions().put("Nov",null); 77 month.getOptions().put("Dec",null); 78 form.addElement("Month", month); 79 80 FormText year = new FormText(page, 240, 660, 300, 680); 85 year.setMaxLength(4); 86 WidgetAnnotation annot = year.getAnnotation(0); 87 year.setAction(Event.KEYPRESS, PDFAction.formJavaScript("AFNumber_Keystroke(0,1,1,0,'',true);")); 88 year.setAction(Event.CHANGE, PDFAction.formJavaScript("AFRange_Validate(true,1900,true,2000);")); 89 form.addElement("Year", year); 90 91 FormRadioButton rating = new FormRadioButton(); 94 95 rating.addAnnotation("1", page, 170,627,180,637); 96 rating.addAnnotation("2", page, 185,627,195,637); 97 rating.addAnnotation("3", page, 200,627,210,637); 98 rating.addAnnotation("4", page, 215,627,225,637); 99 rating.addAnnotation("5", page, 230,627,245,637); 100 form.addElement("Rating", rating); 101 102 FormCheckbox spam = new FormCheckbox(page, 450,627,460,637); 105 form.addElement("Spam", spam); 106 107 FormButton reset = new FormButton(page, 200, 580, 300, 600); 113 WidgetAnnotation widget = reset.getAnnotation(0); 114 widget.setValue("Reset Form"); 115 widget.setAction(Event.CLICK,PDFAction.formReset()); 116 form.addElement("Reset", reset); 117 118 FormButton submit = new FormButton(page, 320, 580, 420, 600); 119 widget = submit.getAnnotation(0); 120 widget.setValue("Submit Form"); 121 widget.setAction(Event.CLICK, PDFAction.formSubmit("http://localhost", PDFAction.METHOD_HTTP_POST)); 122 form.addElement("Submit", submit); 123 124 pdf.render(new FileOutputStream("FormCreation.pdf")); 125 } 126 } 127 | Popular Tags |