java - Is it possible to have space between cells in iTextPdf? -
does itextpdf allow set spacing between cells in table?
i have table 2 columns , trying draw border-bottom on cell. want space between each border same cell padding.
i using below code:
    pdfptable table = new pdfptable(2);     table.settotalwidth(95f);     table.setwidths(new float[]{0.5f,0.5f});     table.sethorizontalalignment(element.align_center);      font fontnormal10 = new font(fontfamily.times_roman, 10, font.normal);     pdfpcell cell = new pdfpcell(new phrase("performance", fontnormal10));     cell.setverticalalignment(element.align_middle);     cell.sethorizontalalignment(element.align_left);     cell.setborder(rectangle.bottom);     cell.setpaddingleft(10f);     cell.setpaddingright(10f);      table.addcell(cell);     table.addcell(cell);     table.addcell(cell);     table.addcell(cell);      document.add(table);   how do this?
you want effect:

that explained in my book, more in presspreviews example.
you need remove borders first:
cell.setborder(pdfpcell.no_border);   and need draw border in cell event:
public class myborder implements pdfpcellevent {     public void celllayout(pdfpcell cell, rectangle position,         pdfcontentbyte[] canvases) {         float x1 = position.getleft() + 2;         float x2 = position.getright() - 2;         float y1 = position.gettop() - 2;         float y2 = position.getbottom() + 2;         pdfcontentbyte canvas = canvases[pdfptable.linecanvas];         canvas.rectangle(x1, y1, x2 - x1, y2 - y1);         canvas.stroke();     } }   you declare cell event cell this:
cell.setcellevent(new myborder());   in example, add or subtract 2 user units cell's dimensions. in case, define padding p , add or subtract p / 2 cell dimensions in pdfpcellevent implementation.
Comments
Post a Comment