/*
* $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 java.awt.Color;
import com.lowagie.text.LwgDocument;
import com.lowagie.text.LwgPageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.LwgPdfPCell;
import com.lowagie.text.pdf.LwgPdfPTable;
import com.lowagie.text.pdf.PdfWriter;
import org.geoforge.demo.GfrFileOutputStream;
/**
* Defining the spacing between the table and other content.
*/
public class TableSpacing {
/**
* Defining the spacing between the table and other content.
*
* @param args
* no arguments needed
*/
public static void main(String[] args) {
System.out.println("TableSpacing");
// step1
LwgDocument document = new LwgDocument(LwgPageSize.A4);
try {
// step2
PdfWriter.getInstance(document,
new GfrFileOutputStream("com.lowagie.examples.objects.tables.TableSpacing.pdf"));
// step3
document.open();
// step4
LwgPdfPTable table = new LwgPdfPTable(3);
LwgPdfPCell cell = new LwgPdfPCell(new Paragraph("header with colspan 3"));
cell.setColspan(3);
table.add(cell);
table.add("1.1");
table.add("2.1");
table.add("3.1");
table.add("1.2");
table.add("2.2");
table.add("3.2");
cell = new LwgPdfPCell(new Paragraph("cell test1"));
cell.setBorderColor(new Color(255, 0, 0));
table.add(cell);
cell = new LwgPdfPCell(new Paragraph("cell test2"));
cell.setColspan(2);
cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
table.add(cell);
table.setWidthPercentage(50);
document.add(new Paragraph("We add 2 tables:"));
document.add(table);
document.add(table);
document.add(new Paragraph("They are glued to eachother"));
document.add(table);
document.add(new Paragraph("This is not very nice. Turn to the next page to see how we solved this"));
document.newPage();
document.add(new Paragraph("We add 2 tables, but with a certain 'SpacingBefore':"));
table.setSpacingBefore(15f);
document.add(table);
document.add(table);
document.add(new Paragraph("Unfortunately, there was no spacing after."));
table.setSpacingAfter(15f);
document.add(table);
document.add(new Paragraph("This is much better, don't you think so?"));
} catch (Exception de) {
de.printStackTrace();
}
// step5
document.close();
}
}