Table Cell Alignment Demo : Table Cell Alignment « PDF RTF « Java






Table Cell Alignment Demo

Table Cell Alignment Demo
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 TableCellAlignmentPDF {
  public static void main(String[] args) {
    Document.compress = false;
    Document document = new Document();
    try {
      PdfWriter.getInstance(document, new FileOutputStream("TableCellAlignmentPDF.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 Default AlignmentTable Cell Default Alignment
2.Table Cell Alignment: Center, MiddleTable Cell Alignment: Center, Middle
3.Cell Alignment BaselineCell Alignment Baseline
4.Cell Alignment CenterCell Alignment Center
5.Cell Alignment JustifiedCell Alignment Justified
6.Cell Alignment MiddleCell Alignment Middle