Continued on / from next page

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

5th November 2015
admin-marketing

Switch code for this example

SimpleTable5.java
  1. /**
  2.  * Example written by Bruno Lowagie in answer to the following question:
  3.  * http://stackoverflow.com/questions/28610545/get-page-number-in-itext
  4.  */
  5. package sandbox.tables;
  6.  
  7. import com.itextpdf.text.Document;
  8. import com.itextpdf.text.DocumentException;
  9. import com.itextpdf.text.PageSize;
  10. import com.itextpdf.text.Phrase;
  11. import com.itextpdf.text.pdf.PdfPCell;
  12. import com.itextpdf.text.pdf.PdfPTable;
  13. import com.itextpdf.text.pdf.PdfWriter;
  14.  
  15. import java.io.File;
  16. import java.io.FileOutputStream;
  17. import java.io.IOException;
  18. import sandbox.WrapToTest;
  19.  
  20. @WrapToTest
  21. public class SimpleTable5 {
  22.     public static final String DEST = "results/tables/simple_table5.pdf";
  23.  
  24.     public static void main(String[] args) throws IOException,
  25.             DocumentException {
  26.         File file = new File(DEST);
  27.         file.getParentFile().mkdirs();
  28.         new SimpleTable5().createPdf(DEST);
  29.     }
  30.     public void createPdf(String dest) throws IOException, DocumentException {
  31.         Document document = new Document(PageSize.A4.rotate());
  32.         PdfWriter.getInstance(document, new FileOutputStream(dest));
  33.         document.open();
  34.         PdfPTable table = new PdfPTable(5);
  35.         table.setWidthPercentage(100);
  36.         PdfPCell cell = new PdfPCell(new Phrase("Table XYZ (Continued)"));
  37.         cell.setColspan(5);
  38.         table.addCell(cell);
  39.         cell = new PdfPCell(new Phrase("Continue on next page"));
  40.         cell.setColspan(5);
  41.         table.addCell(cell);
  42.         table.setHeaderRows(2);
  43.         table.setFooterRows(1);
  44.         table.setSkipFirstHeader(true);
  45.         table.setSkipLastFooter(true);
  46.         for (int i = 0; i < 350; i++) {
  47.             table.addCell(String.valueOf(i+1));
  48.         }
  49.         document.add(table);
  50.         document.close();
  51.     }
  52.  
  53. }
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