PdfPTable and PdfTemplate

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

31st May 2016
admin-marketing

Switch code for this example

TableTemplate.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/22093993/itext-whats-an-easy-to-print-first-right-then-down
  11.  */
  12. package com.itextpdf.samples.sandbox.tables;
  13.  
  14. import com.itextpdf.kernel.geom.Rectangle;
  15. import com.itextpdf.kernel.pdf.PdfDocument;
  16. import com.itextpdf.kernel.pdf.PdfWriter;
  17. import com.itextpdf.kernel.pdf.canvas.PdfCanvas;
  18. import com.itextpdf.kernel.pdf.xobject.PdfFormXObject;
  19. import com.itextpdf.layout.Canvas;
  20. import com.itextpdf.layout.element.Cell;
  21. import com.itextpdf.layout.element.Paragraph;
  22. import com.itextpdf.layout.element.Table;
  23. import com.itextpdf.samples.GenericTest;
  24. import com.itextpdf.test.annotations.type.SampleTest;
  25.  
  26. import org.junit.experimental.categories.Category;
  27.  
  28. import java.io.File;
  29.  
  30. @Category(SampleTest.class)
  31. public class TableTemplate extends GenericTest {
  32.     public static final String DEST = "./target/test/resources/sandbox/tables/table_template.pdf";
  33.  
  34.     public static void main(String[] args) throws Exception {
  35.         File file = new File(DEST);
  36.         file.getParentFile().mkdirs();
  37.         new TableTemplate().manipulatePdf(DEST);
  38.     }
  39.  
  40.     @Override
  41.     protected void manipulatePdf(String dest) throws Exception {
  42.         PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
  43.  
  44.         Table table = new Table(15);
  45.         table.setWidth(1500);
  46.         Cell cell;
  47.         for (int r = 'A'; r
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