/*
* $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.LwgRectangle;
import com.lowagie.text.pdf.LwgPdfPCell;
import com.lowagie.text.pdf.LwgPdfPTable;
import com.lowagie.text.pdf.PdfWriter;
import org.geoforge.demo.GfrFileOutputStream;
/**
* The Cell is derived from the LwgRectangle object, so we can do all kinds of things with the borders and colors.
*/
public class CellColors {
/**
* LwgRectangle operations.
*
* @param args
* no arguments needed
*/
public static void main(String[] args) {
System.out.println("Rectangle methods on PdfPCell");
// step1
LwgDocument document = new LwgDocument(LwgPageSize.A4);
try {
// step2
PdfWriter.getInstance(document,
new GfrFileOutputStream("com.lowagie.examples.objects.tables.CellColors.pdf"));
// step3
document.open();
// step4
LwgPdfPTable table = new LwgPdfPTable(4);
LwgPdfPCell cell;
cell = new LwgPdfPCell(new Paragraph("test colors:"));
table.add(cell);
cell = new LwgPdfPCell(new Paragraph("red"));
cell.setBorder(LwgRectangle.NO_BORDER);
cell.setBackgroundColor(Color.red);
table.add(cell);
cell = new LwgPdfPCell(new Paragraph("green"));
cell.setBorder(LwgRectangle.BOTTOM);
cell.setBorderColorBottom(Color.magenta);
cell.setBorderWidthBottom(10f);
cell.setBackgroundColor(Color.green);
table.add(cell);
cell = new LwgPdfPCell(new Paragraph("blue"));
cell.setBorder(LwgRectangle.TOP);
cell.setUseBorderPadding(true);
cell.setBorderWidthTop(5f);
cell.setBorderColorTop(Color.cyan);
cell.setBackgroundColor(Color.blue);
table.add(cell);
cell = new LwgPdfPCell(new Paragraph("test GrayFill:"));
table.add(cell);
cell = new LwgPdfPCell(new Paragraph("0.25"));
cell.setBorder(LwgRectangle.NO_BORDER);
cell.setGrayFill(0.25f);
table.add(cell);
cell = new LwgPdfPCell(new Paragraph("0.5"));
cell.setBorder(LwgRectangle.NO_BORDER);
cell.setGrayFill(0.5f);
table.add(cell);
cell = new LwgPdfPCell(new Paragraph("0.75"));
cell.setBorder(LwgRectangle.NO_BORDER);
cell.setGrayFill(0.75f);
table.add(cell);
document.add(table);
} catch (Exception de) {
de.printStackTrace();
}
// step5
document.close();
}
}