Using the Table class for reports creation

import java.lang.*;
import java.io.*;
import java.util.*;

import com.pdfjet.*;


/**
 *  Example_08.java
 *
 */
public class Example_08 {

    public Example_08() throws Exception {
        PDF pdf = new PDF();
        Font f1 = new Font(pdf, "Helvetica-Bold");
        Font f2 = new Font(pdf, "Helvetica");
        Font f3 = new Font(pdf, "Helvetica-BoldOblique");
        // Please note:
        // All font and image objects must be created before the first page.

        Page page = new Page(pdf, Letter.PORTRAIT);
        f1.setSize(7.0);
        f2.setSize(7.0);
        f3.setSize(7.0);

        Table table = new Table(f1, f2);
        table.setData(
                "data/world-communications.txt",
                "|",
                Table.DATA_HAS_2_HEADER_ROWS);
        table.setLineWidth(0.2);
        table.setPosition(70.0, 30.0);
        table.setTextColorInRow(6, RGB.BLUE);
        table.setTextColorInRow(39, RGB.RED);
        table.setTextFontInRow(26, f3, 7);
        table.removeLineBetweenRows(0, 1);
        table.autoAdjustColumnWidths();
        table.setWidthForColumn(0, 120);
        table.rightAlignNumbers();
        int numOfPages = table.getNumberOfPages(page);
        while (true) {
            table.drawOn(page);
            // TO DO: Draw "Page 1 of N" here
            if (!table.hasMoreData()) break;
            page = new Page(pdf, Letter.PORTRAIT);
        }

        pdf.wrap();
        pdf.save("Example_08.pdf");
    }


    public static void main(String[] args) {
        try {
            new Example_08();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}   // End of Example_08.java
Example_08.pdf

© 2007 Innovatics Inc.