iText in Action: Chapter 5: Table, cell, and page events


If you compile and execute this example, you'll get the following result:

You can download the full source code of NewPage, or read it here:

 * This class is part of the book "iText in Action - 2nd Edition"
 * written by Bruno Lowagie (ISBN: 9781935182610)
 * For more info, go to:
 * This example only works with the AGPL version of iText.
package part1.chapter05;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
public class NewPage {
    /** Path to the resulting PDF file. */
    public static final String RESULT
        = "results/part1/chapter05/new_page.pdf";
     * Main method creating the PDF.
     * @param    args    no arguments needed
     * @throws IOException 
     * @throws DocumentException 
    public static void main(String[] args) throws IOException, DocumentException {
    	// step 1
        Document document = new Document();
        // step 2
        PdfWriter writer
            = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        // step 3;
        // step 4
        document.add(new Paragraph("This page will NOT be followed by a blank page!"));
        // we don't add anything to this page: newPage() will be ignored
        document.add(new Paragraph("This page will be followed by a blank page!"));
        document.add(new Paragraph("The previous page was a blank page!"));
        // step 5
Powered by GeSHi

The NewPage example is part of the book iText in Action (ISBN 9781935182610).

It's a small standalone application. You can use this example for inspiration, but please read the book if there's something you don't understand about the example. You'll find more info in Chapter 5.

Keywords for this example: Blank page, New page

If you want this example to work, you need the following jars: iText.jar