1 import org.faceless.pdf2.*; 2 import java.io.*; 3 import java.awt.Color ; 4 5 public class FormFill 16 { 17 public static void main(String [] args) 18 throws IOException 19 { 20 PDF pdf = new PDF(new PDFReader(new FileInputStream("FormCreation.pdf"))); 23 Form form = pdf.getForm(); 24 25 ((FormText)form.getElement("Name")).setValue("John Tester"); 28 ((FormText)form.getElement("Address")).setValue("12 Test St\nTestville\nTestLand"); 29 ((FormText)form.getElement("Year")).setValue("1960"); 30 ((FormChoice)form.getElement("Month")).setValue("May"); 31 ((FormRadioButton)form.getElement("Rating")).setValue("2"); 32 ((FormCheckbox)form.getElement("Spam")).setValue("Yes"); 33 34 PDFStyle bg = new PDFStyle(); 39 PDFStyle fg = new PDFStyle(); 40 bg.setFillColor(Color.yellow); 41 bg.setLineColor(Color.red); 42 bg.setFormStyle(PDFStyle.FORMSTYLE_SOLID); 43 fg.setFont(new StandardFont(StandardFont.TIMES), 12); 44 fg.setFillColor(Color.black); 45 WidgetAnnotation widget = form.getElement("Submit").getAnnotation(0); 46 widget.setTextStyle(fg); 47 widget.setBackgroundStyle(bg); 48 49 pdf.render(new FileOutputStream("FormFill.pdf")); 52 } 53 } 54 | Popular Tags |