|
In the FloatingBoxes example Demonstrates how to
simulate cellspacing as in HTML.
How can be modified borderWidth in
FloatingBoxes example, for each cell individually ?
I am sending You the FloatingBoxes example which I have mofied to set the borderWidth( but it is not worked correctly): public class FloatingBoxes implements
PdfPCellEvent, PdfPTableEvent {
public float space =
10;
public static int colCount = 3; public void tableLayout(PdfPTable table,
float[][] width, float[] height,
int headerRows, int rowStart, PdfContentByte[] canvases) { float widths[] = width[0]; float x1 = widths[0] - space/2; float x2 = widths[widths.length - 1] + space/2; float y1 = height[0] + space/2; float y2 = height[height.length - 1] - space/2; PdfContentByte canvas = canvases[PdfPTable.LINECANVAS]; canvas.setRGBColorStroke(0x00, 0x00, 0xFF); canvas.rectangle(x1, y1, x2 - x1, y2 - y1); canvas.stroke(); } public void cellLayout(PdfPCell cell, Rectangle
position,
PdfContentByte[] canvases) { float x1 = position.left() + space/2; float x2 = position.right() - space/2; float y1 = position.top() - space/2; float y2 = position.bottom() + space/2 ; PdfContentByte canvas = canvases[PdfPTable.LINECANVAS]; canvas.createPattern(10f, 10f, java.awt.Color.BLUE); canvas.setRGBColorStroke(0xFF, 0x00, 0x00); canvas.rectangle(x1, y1, x2 - x1, y2 - y1); canvas.stroke(); canvas.resetRGBColorStroke(); } public static void main(String[] args)
{
FloatingBoxes floatingBoxes = new FloatingBoxes(); // step 1 Document document = new Document(); try { // step 2 PdfWriter.getInstance(document, new FileOutputStream( "FloatingBoxes.pdf")); // step 3 document.open(); // step 4 PdfPTable table = new PdfPTable(colCount); table.setTableEvent(floatingBoxes); PdfPCell pCell = new PdfPCell(); pCell.setCellEvent(floatingBoxes); pCell.setBorder(Rectangle.NO_BORDER); pCell.setPadding(5f); pCell.addElement(new Chunk("value")); pCell.setBorderWidth(5); table.addCell(pCell); pCell = new PdfPCell(); pCell.setCellEvent(floatingBoxes); pCell.setBorder(Rectangle.NO_BORDER); pCell.setPadding(5f); pCell.addElement(new Chunk("name")); pCell.setBorderWidth(2); table.addCell(pCell); pCell = new PdfPCell(); pCell.setCellEvent(floatingBoxes); pCell.setBorder(Rectangle.NO_BORDER); pCell.setPadding(5f); pCell.addElement(new Chunk("dog")); pCell.setBorderWidth(5); table.addCell(pCell); document.add(table); } catch (DocumentException de)
{
System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } // step 5 document.close(); } }
|
- [iText-questions] iTExt Karen Vardanyan
- [iText-questions] iText Christophe Folschette
