Table Cell with Background : Table Cell Color « PDF RTF « Java






Table Cell with Background

Table Cell with Background
import java.awt.Color;
import java.io.FileOutputStream;

import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.Element;
import com.lowagie.text.Image;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;

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

      document.open();

      Image img = Image.getInstance("logo.png");
      img.scalePercent(10);
      
      PdfPTable table = new PdfPTable(3);
      PdfPCell cell = new PdfPCell();
      cell.addElement(new Chunk("cell "));
      cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
      cell.setHorizontalAlignment(Element.ALIGN_CENTER);

      table.addCell("a cell");
      table.addCell(cell);
      table.addCell("a cell");

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

           
       








itext.zip( 1,748 k)

Related examples in the same category

1.Table Cell Color DemoTable Cell Color Demo
2.Cell Gray ScaleCell Gray Scale