/*
* $Id$
*
* This code is part of the 'iText Tutorial'.
* You can find the complete tutorial at the following address:
* http://itextdocs.lowagie.com/tutorial/
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* itext-questions@lists.sourceforge.net
*/
package com.lowagie.examples.objects.tables;
import com.lowagie.text.LwgDocument;
import com.lowagie.text.LwgElement;
import com.lowagie.text.LwgPageSize;
import com.lowagie.text.pdf.LwgPdfPTable;
import com.lowagie.text.pdf.PdfWriter;
import org.geoforge.demo.GfrFileOutputStream;
/**
* Add a big table to a PDF with document.add().
*/
public class AddBigTable {
/**
* Big PdfPTable with document.add().
*
* @param args
* no arguments needed
*/
public static void main(String[] args) {
System.out.println("document.add(BigTable)");
// step1
LwgDocument document = new LwgDocument(LwgPageSize.A4.rotate(), 10, 10, 10, 10);
try {
// step2
PdfWriter.getInstance(document,
new GfrFileOutputStream("com.lowagie.examples.objects.tables.AddBigTable.pdf"));
// step3
document.open();
// step4
String[] bogusData = { "M0065920", "SL", "FR86000P", "PCGOLD",
"119000", "96 06", "2001-08-13", "4350", "6011648299",
"FLFLMTGP", "153", "119000.00" };
int NumColumns = 12;
LwgPdfPTable datatable = new LwgPdfPTable(NumColumns);
int headerwidths[] = { 9, 4, 8, 10, 8, 11, 9, 7, 9, 10, 4, 10 }; // percentage
datatable.setWidths(headerwidths);
datatable.setWidthPercentage(100); // percentage
datatable.getDefaultCell().setPadding(3);
datatable.getDefaultCell().setBorderWidth(2);
datatable.getDefaultCell().setHorizontalAlignment(
LwgElement.ALIGN_CENTER);
datatable.add("Clock #");
datatable.add("Trans Type");
datatable.add("Cusip");
datatable.add("Long Name");
datatable.add("Quantity");
datatable.add("Fraction Price");
datatable.add("Settle Date");
datatable.add("Portfolio");
datatable.add("ADP Number");
datatable.add("Account ID");
datatable.add("Reg Rep ID");
datatable.add("Amt To Go ");
datatable.setHeaderRows(1); // this is the end of the table header
datatable.getDefaultCell().setBorderWidth(1);
for (int i = 1; i < 750; i++) {
if (i % 2 == 1) {
datatable.getDefaultCell().setGrayFill(0.9f);
}
for (int x = 0; x < NumColumns; x++) {
datatable.add(bogusData[x]);
}
if (i % 2 == 1) {
datatable.getDefaultCell().setGrayFill(1);
}
}
document.add(datatable);
} catch (Exception de) {
de.printStackTrace();
}
// step5
document.close();
}
}