MainClass.java Source code

Java tutorial

Introduction

Here is the source code for MainClass.java

Source

import java.io.FileOutputStream;

import com.lowagie.text.Document;
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();
        PdfPTable table = new PdfPTable(10);
        for (int k = 1; k <= 100; ++k) {
            table.addCell("number " + k);
        }
        table.setTotalWidth(800);
        table.writeSelectedRows(0, 5, 0, -1, 50, 650, writer.getDirectContent());
        document.newPage();
        table.writeSelectedRows(5, -1, 0, -1, 50, 650, writer.getDirectContent());
        document.close();
    }
}