implements PdfPCellEvent : Table Cell « PDF « Java Tutorial






import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.Element;
import com.lowagie.text.Phrase;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.GrayColor;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPCellEvent;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;

class RoundRectangle implements PdfPCellEvent {
  public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvas) {
    PdfContentByte cb = canvas[PdfPTable.LINECANVAS];
    cb.setColorStroke(new GrayColor(0.8f));
    cb.roundRectangle(rect.left() + 4, rect.bottom(), rect.width() - 8, rect.height() - 4, 4);
    cb.stroke();
  }
}

public class MainClass {

  public static void main(String[] args) throws Exception {
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    document.open();
    RoundRectangle border = new RoundRectangle();

    PdfPTable table = new PdfPTable(6);
    PdfPCell cell;
    for (int i = 1; i <= 30; i++) {
      cell = new PdfPCell(new Phrase("day " + i));
      cell.setHorizontalAlignment(Element.ALIGN_CENTER);
      cell.setBorder(Rectangle.NO_BORDER);
      cell.setPadding(4);
      cell.setCellEvent(border);
      table.addCell(cell);
    }
    document.add(table);
    document.close();
  }
}








29.55.Table Cell
29.55.1.Image is scaled
29.55.2.Scaled Image with no padding
29.55.3.Not scaled Image
29.55.4.Add content to table cell
29.55.5.Set width percentage
29.55.6.Change table cell background color
29.55.7.Set table column width
29.55.8.Rotate a table cell
29.55.9.Auto Fill Empty cells
29.55.10.Set table cell no wrap
29.55.11.Set table cell fixed height
29.55.12.Set table cell minimun height
29.55.13.Set alignment for Table cell
29.55.14.Add paragraph to table cell with alignment setting
29.55.15.Add paragraph of first line indented to a table cell
29.55.16.Table alignment: bottom, middle and top
29.55.17.Set leading for table cell
29.55.18.Set padding for table cell
29.55.19.Set left, right, top and bottom padding for table cell
29.55.20.Table cell ascender and descender
29.55.21.Table cell without border
29.55.22.Cell border color and background color
29.55.23.implements PdfPCellEvent