How to Create the Table With Multiple Rows In Pdf in java


In this core java tutorial we will learn How to Create the Table With Multiple Rows In Pdf in java - using iText library - core java tutorial in Java with program and examples.



We will create PdfPTable (com.itextpdf.text.pdf.PdfPTable) with 2 columns (new PdfPTable(2)) and then create 6 cells ( com.itextpdf.text.pdf.PdfPCell) and then add all those cells to table and 3 rows will be created in java in pdf in itext in java.

We will generate PDF files in java using iText library. PDF files can be generated dynamically in java using iText library.


How to Create the Table In Pdf in java - iText java tutorial

Create Greek List In pdf in java using iText - iText java tutorial

How to Create Password Protected Pdf in java - iText Example

How to add TEXT as Watermark In Pdf in java - iText java tutorial



Download jars required to execute program >

Or, you may download jars from here.


Program/Example How to Create the Table With Multiple Rows In Pdf in java - Using iText library - core java tutorial

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import com.itextpdf.text.Document;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
/**
*
*  Creating the Table With Multiple Rows In Pdf Example
*  Using iText library - core java tutorial
*
*/
public class CreateTableWithMultipleRowsInPdfExample {
   public static void main(String[] args) {
          try {
                 String pdfFilePath = "e:/Create Table With Multiple Rows In Pdf Example.pdf";
                 OutputStream fos = new FileOutputStream(new File(pdfFilePath));
                 Document document = new Document();
                 PdfWriter.getInstance(document, fos);
                 document.open();
                 /**
                 * Now, we will create table in PDF file
                 */
                 PdfPTable table = new PdfPTable(2); // Create 2 columns in table.
                 // Create cells
                 PdfPCell cell1 = new PdfPCell(new Paragraph("Cell 1"));
                 PdfPCell cell2 = new PdfPCell(new Paragraph("Cell 2"));
                 PdfPCell cell3 = new PdfPCell(new Paragraph("Cell 3"));
                 PdfPCell cell4 = new PdfPCell(new Paragraph("Cell 4"));
                 PdfPCell cell5 = new PdfPCell(new Paragraph("Cell 5"));
                 PdfPCell cell6 = new PdfPCell(new Paragraph("Cell 6"));
                 // Add cells in table
                 table.addCell(cell1);
                 table.addCell(cell2);
                 table.addCell(cell3);
                 table.addCell(cell4);
                 table.addCell(cell5);
                 table.addCell(cell6);
                 // Add table in document
                 document.add(table);
                 document.close();
                 fos.close();
                 System.out.println("PDF created in >> " + pdfFilePath);
          } catch (Exception e) {
                 e.printStackTrace();
          }
   }
}
/* Output of above program
PDF created in >> e:/Create Table With Multiple Rows In Pdf Example.pdf
*/



PDF formed after executing above java program(How to Create the Table With Multiple Rows In Pdf in java) will look like this >


Summary -
So in this core java tutorial we learned How to Create the Table With Multiple Rows In Pdf in java - using iText library - core java tutorial in Java with program and examples.
We created PdfPTable (com.itextpdf.text.pdf.PdfPTable) with 2 columns (new PdfPTable(2)) and then created 6 cells ( com.itextpdf.text.pdf.PdfPCell) and then added all those cells to table and 3 rows were created in java in pdf in itext in java.




Having any doubt? or you you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.

References >



RELATED LINKS>

iText library tutorial in java - How to Create and work with PDF files in java


Creating first pdf and setting attributes using itext in java - iText tutorial >

Create the first Pdf Example Using iText library in java - iText java tutorial example

Setting Pdf Attributes like Title, Author, Creator, subject, Keywords, Header and CreationDate in java



Creating TABLES in pdf in java - iText tutorial >

How to Create the Table In Pdf in java - iText java tutorial

How to do the Cell Alignment In Pdf generated table in Java program

How to Set Cell Background Colour In Pdf Table in java example

How to Set Cell Background Colour In Pdf Table in java - iText java tutorial

How to Create Images In Pdf generated Table in java itext

How to Create Nested Tables in Pdf in java - iText java tutorial

How to Create the Table With Multiple Rows In Pdf in java program

Creating IMAGES in pdf in java - iText tutorial >

Adding the Images In Pdf in java example using iText - iText java tutorial

How to Add And Rotate Images In Pdf in java - iText java tutorial example

How can you Add the Images from URL In Pdf in java program





Adding WATERMARK in pdf in java - iText tutorial >

How to add TEXT as Watermark In Pdf in java - iText java tutorial

How to add IMAGE as Watermark In Pdf in iText in java example



Creating CHAPTER, SECTION, CHUNK, PARAGRAPH AND PHRASE in pdf in java - iText tutorial >

Create Chapter And Section In Pdf in java - iText java tutorial

Create Chunk In Pdf in java - iText java tutorial program

how to Create Paragraph In Pdf - iText java tutorial program

Create Left, center and right aligned Paragraph In Pdf - iText java tutorial

Create Phrase In Pdf (with lead) Using Itext - iText java tutorial example




eEdit
Must read for you :