Mega Code Archive

 
Categories / Java Tutorial / PDF
 

Split Table Rows

import java.io.FileOutputStream; import java.io.IOException; import com.lowagie.text.Document; import com.lowagie.text.DocumentException; import com.lowagie.text.PageSize; import com.lowagie.text.Paragraph; import com.lowagie.text.pdf.PdfPCell; import com.lowagie.text.pdf.PdfPTable; import com.lowagie.text.pdf.PdfWriter; public class MainClass {   public static void main(String[] args) throws Exception {     Document document1 = new Document(PageSize.A4.rotate());       PdfWriter.getInstance(document1, new FileOutputStream(           "2.pdf"));       document1.open();       String text = "Quick brown fox jumps over the lazy dog.";       PdfPTable table = new PdfPTable(2);       PdfPCell largeCell = new PdfPCell();       for (int i = 1; i < 13; i++) {         largeCell.addElement(new Paragraph(String.valueOf(i) + text));       }       for (int i = 1; i < 11; i++) {          table.addCell(largeCell);       }       document1.add(table);       table.setSplitLate(false);       document1.add(table);       table.setSplitRows(false);       document1.add(table);     document1.close();   } }