1 import org.faceless.pdf2.*; 2 import java.io.*; 3 4 public class BatchFormFill 9 { 10 private static class Person 14 { 15 public final String name, country, phone; 16 17 public Person(String name, String country, String phone) 18 { 19 this.name=name; 20 this.country=country; 21 this.phone=phone; 22 } 23 } 24 25 public static void main(String [] args) throws IOException 30 { 31 Person[] people = { new Person("John Bull", "UK", "442078868199"), 32 new Person("Ben Franklin", "US", "12125551234"), 33 new Person("Werner Graf", "DE", "49691234567"), 34 new Person("Jean Reno", "FR", "3325123916"), 35 new Person("Dmitri Papadolou", "GR", "3017891234") 36 }; 37 38 FileInputStream in = new FileInputStream("resources/fw8eci.pdf"); 39 PDF template = new PDF(new PDFReader(in)); 40 in.close(); 41 42 for (int i=0;i<people.length;i++) { 43 createPDF(i, people[i], template); 44 } 45 } 46 47 static final void createPDF(int i, Person person, PDF template) throws IOException 52 { 53 61 PDF pdf = new PDF(template); 62 Form form = pdf.getForm(); 63 ((FormText)form.getElement("f1-1")).setValue(person.name); 64 ((FormText)form.getElement("f1-2")).setValue(person.country); 65 ((FormText)form.getElement("f1-3")).setValue(person.phone); 66 67 form.flatten(); 72 73 System.out.println("Writing \"BatchForm-"+i+".pdf\""); 74 FileOutputStream out = new FileOutputStream("BatchForm-"+i+".pdf"); 75 pdf.render(out); 76 out.close(); 77 } 78 } 79 | Popular Tags |