Set table total width : Table Row « PDF « Java Tutorial






import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Iterator;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfPRow;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;

public class MainClass {
  public static void main(String[] args) throws Exception {
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    document.open();
    PdfContentByte cb = writer.getDirectContent();
    PdfPTable table = new PdfPTable(2);
    float[] rows = { 50f, 250f };
    table.setTotalWidth(rows);
    for (int k = 0; k < 200; ++k) {
      table.addCell("row " + k);
      table.addCell("blah " + k);
    }
    document.add(new Paragraph("row 0 - 50"));
    table.writeSelectedRows(0, 50, 150, 820, cb);
   document.close();
  }
}








29.57.Table Row
29.57.1.Split Table Rows
29.57.2.Set table total width
29.57.3.Write Selected Rows in a Table
29.57.4.What if table is larger than the page
29.57.5.Ouput selected rows from a table
29.57.6.Loop through all rows from Table