PdfPTable and PdfTemplate

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

5th November 2015
admin-marketing

Switch code for this example

TableTemplate.java
  1. /**
  2.  * Example written by Bruno Lowagie in answer to the following question:
  3.  * http://stackoverflow.com/questions/22093993/itext-whats-an-easy-to-print-first-right-then-down
  4.  */
  5. package sandbox.tables;
  6.  
  7. import com.itextpdf.text.Document;
  8. import com.itextpdf.text.DocumentException;
  9. import com.itextpdf.text.Paragraph;
  10. import com.itextpdf.text.pdf.PdfContentByte;
  11. import com.itextpdf.text.pdf.PdfPCell;
  12. import com.itextpdf.text.pdf.PdfPTable;
  13. import com.itextpdf.text.pdf.PdfTemplate;
  14. import com.itextpdf.text.pdf.PdfWriter;
  15.  
  16. import java.io.File;
  17. import java.io.FileOutputStream;
  18. import java.io.IOException;
  19.  
  20. import sandbox.WrapToTest;
  21.  
  22. @WrapToTest
  23. public class TableTemplate {
  24.    
  25.     public static final String DEST = "results/tables/table_template.pdf";
  26.    
  27.     public static void main(String[] args) throws IOException, DocumentException {
  28.         File file = new File(DEST);
  29.         file.getParentFile().mkdirs();
  30.         new TableTemplate().createPdf(DEST);
  31.     }
  32.    
  33.     public void createPdf(String dest) throws IOException, DocumentException {
  34.         Document document = new Document();
  35.         PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(dest));
  36.         document.open();
  37.         PdfPTable table = new PdfPTable(15);
  38.         table.setTotalWidth(1500);
  39.         PdfPCell cell;
  40.         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