Continued on / from next page

This is a code example of iText PDF, discover more.

31st May 2016
iText PDF

Switch code for this example

SimpleTable5.java
  1. /*
  2.  
  3.     This file is part of the iText (R) project.
  4.     Copyright (c) 1998-2016 iText Group NV
  5.  
  6. */
  7.  
  8. /**
  9.  * Example written by Bruno Lowagie in answer to the following question:
  10.  * http://stackoverflow.com/questions/28610545/get-page-number-in-itext
  11.  */
  12. package com.itextpdf.samples.sandbox.tables;
  13.  
  14. import com.itextpdf.kernel.geom.PageSize;
  15. import com.itextpdf.kernel.pdf.PdfDocument;
  16. import com.itextpdf.kernel.pdf.PdfWriter;
  17. import com.itextpdf.layout.Document;
  18. import com.itextpdf.layout.element.Cell;
  19. import com.itextpdf.layout.element.Table;
  20. import com.itextpdf.samples.GenericTest;
  21. import com.itextpdf.test.annotations.type.SampleTest;
  22.  
  23. import org.junit.experimental.categories.Category;
  24.  
  25. import java.io.File;
  26.  
  27. @Category(SampleTest.class)
  28. public class SimpleTable5 extends GenericTest {
  29.     public static final String DEST = "./target/test/resources/sandbox/tables/simple_table5.pdf";
  30.  
  31.     public static void main(String[] args) throws Exception {
  32.         File file = new File(DEST);
  33.         file.getParentFile().mkdirs();
  34.         new SimpleTable5().manipulatePdf(DEST);
  35.     }
  36.  
  37.     @Override
  38.     protected void manipulatePdf(String dest) throws Exception {
  39.         PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
  40.         // Note that it is not necessary to create new PageSize object,
  41.         // but for testing reasons (connected to parallelization) we call constructor here
  42.         Document doc = new Document(pdfDoc, new PageSize(PageSize.A4).rotate());
  43.  
  44.         Table table = new Table(5);
  45.         Cell cell = new Cell(1, 5).add("Table XYZ (Continued)");
  46.         table.addHeaderCell(cell);
  47.         cell = new Cell(1, 5).add("Continue on next page");
  48.         table.addFooterCell(cell);
  49.         table.setSkipFirstHeader(true);
  50.         table.setSkipLastFooter(true);
  51.         for (int i = 0; i < 350; i++) {
  52.             table.addCell(String.valueOf(i + 1));
  53.         }
  54.  
  55.         doc.add(table);
  56.  
  57.         doc.close();
  58.     }
  59. }
Contact

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now