/* * This class is part of the book "iText in Action - 2nd Edition" * written by Bruno Lowagie (ISBN: 9781935182610) * For more info, go to: http://itextpdf.com/examples/ * This example only works with the AGPL version of iText. */ package part1.chapter04; import java.io.FileOutputStream; import java.io.IOException; import java.sql.Date; import java.sql.SQLException; import java.util.List; import com.lowagie.database.DatabaseConnection; import com.lowagie.database.HsqldbConnection; import com.lowagie.filmfestival.PojoFactory; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.PageSize; import com.itextpdf.text.pdf.PdfPTable; import com.itextpdf.text.pdf.PdfWriter; public class HeaderFooter2 extends HeaderFooter1 { /** The resulting PDF file. */ public static final String RESULT = "results/part1/chapter04/header_footer_2.pdf"; /** * Creates a PDF document. * @param filename the path to the new PDF document * @throws DocumentException * @throws IOException * @throws SQLException */ public void createPdf(String filename) throws SQLException, DocumentException, IOException { // create a database connection DatabaseConnection connection = new HsqldbConnection("filmfestival"); // step 1 Document document = new Document(PageSize.A4.rotate()); // step 2 PdfWriter.getInstance(document, new FileOutputStream(filename)); // step 3 document.open(); // step 4 List days = PojoFactory.getDays(connection); for (Date day : days) { PdfPTable table = getTable(connection, day); table.setSplitLate(false); document.add(table); document.newPage(); } // step 5 document.close(); // close the database connection connection.close(); } /** * Main method. * @param args no arguments needed * @throws DocumentException * @throws IOException * @throws SQLException */ public static void main(String[] args) throws SQLException, DocumentException, IOException { new HeaderFooter2().createPdf(RESULT); } }