PaddingBordersPDF.java Source code

Java tutorial

Introduction

Here is the source code for PaddingBordersPDF.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 PaddingBordersPDF {
    public static void main(String[] args) {
        Document document = new Document();
        try {
            PdfWriter.getInstance(document, new FileOutputStream("PaddingBordersPDF.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");
            document.add(table);
        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
        document.close();
    }
}