/*
* $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 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;
/**
* Changing the padding and the leading of the content of a PdfPCell.
*/
public class CellPaddingLeading {
/**
* Changing padding and leading.
*
* @param args
* no arguments needed
*/
public static void main(String[] args) {
System.out.println("padding - leading");
// step1
LwgDocument document = new LwgDocument(LwgPageSize.A4.rotate(), 10, 10, 10, 10);
try {
// step2
PdfWriter.getInstance(document,
new GfrFileOutputStream("com.lowagie.examples.objects.tables.CellPaddingLeading.pdf"));
// step3
document.open();
// step4
LwgPdfPTable table = new LwgPdfPTable(2);
LwgPdfPCell cell;
Paragraph p = new Paragraph("Quick brown fox jumps over the lazy dog. Quick brown fox jumps over the lazy dog.");
table.add("default");
table.add(p);
table.add("padding 10");
cell = new LwgPdfPCell(p);
cell.setPadding(10f);
table.add(cell);
table.add("no padding at all");
cell = new LwgPdfPCell(p);
cell.setPadding(0f);
table.add(cell);
table.add("no padding at the top; large padding at the left");
cell = new LwgPdfPCell(p);
cell.setPaddingTop(0f);
cell.setPaddingLeft(20f);
table.add(cell);
document.add(table);
document.newPage();
table = new LwgPdfPTable(2);
table.add("no leading at all");
table.getDefaultCell().setLeading(0f, 0f);
table.add("blah blah\nblah blah blah\nblah blah\nblah blah blah\nblah blah\nblah blah blah\nblah blah\nblah blah blah\n");
table.getDefaultCell().setLeading(14f, 0f);
table.add("fixed leading of 14pt");
table.add("blah blah\nblah blah blah\nblah blah\nblah blah blah\nblah blah\nblah blah blah\nblah blah\nblah blah blah\n");
table.add("relative leading of 1.0 times the fontsize");
table.getDefaultCell().setLeading(0f, 1.0f);
table.add("blah blah\nblah blah blah\nblah blah\nblah blah blah\nblah blah\nblah blah blah\nblah blah\nblah blah blah\n");
document.add(table);
} catch (Exception de) {
de.printStackTrace();
}
// step5
document.close();
}
}