Convert2pdfptable.java Source code

Java tutorial

Introduction

Here is the source code for Convert2pdfptable.java

Source

import java.io.FileOutputStream;

import com.lowagie.text.Cell;
import com.lowagie.text.Document;
import com.lowagie.text.Table;
import com.lowagie.text.pdf.PdfWriter;

public class Convert2pdfptable {
    public static void main(String[] args) {
        Document document = new Document();
        try {
            PdfWriter.getInstance(document, new FileOutputStream("Convert2pdfptable.pdf"));

            document.open();

            Table table = new Table(2);
            table.setBorderWidth(1);
            table.setPadding(10);
            Cell cell = new Cell("header");
            cell.setHeader(true);
            cell.setColspan(2);
            table.addCell(cell);
            table.addCell("1.1");
            table.addCell("2.1");

            table.addCell("3.1");
            table.addCell("1.2");

            table.addCell("2.2");
            table.addCell("3.2");
            table.setConvert2pdfptable(true);
            document.add(table);

        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
        document.close();
    }
}