public void writeBorderAndBackgroung(float xPos, float yPos, PdfPCell cell, PdfContentByte[] canvases) { PdfContentByte lines = canvases[PdfPTable.LINECANVAS]; PdfContentByte backgr = canvases[PdfPTable.BACKGROUNDCANVAS]; // the coordinates of the border are retrieved float x1 = cell.Left + xPos; float y1 = cell.Top + yPos; float x2 = cell.Right + xPos; float y2 = y1 - maxHeight; // the backgroundcolor is set Color background = cell.BackgroundColor; if (background != null) { backgr.ColorFill = background; backgr.rectangle(x1, y1, x2 - x1, y2 - y1); backgr.fill(); } else if (cell.GrayFill > 0) { backgr.GrayFill = cell.GrayFill; backgr.rectangle(x1, y1, x2 - x1, y2 - y1); backgr.fill(); } // if the element hasn't got any borders, nothing is added if (cell.hasBorders()) { // the width is set to the width of the element if (cell.BorderWidth != Rectangle.UNDEFINED) { lines.LineWidth = cell.BorderWidth; } // the color is set to the color of the element Color color = cell.BorderColor; if (color != null) { lines.ColorStroke = color; } // if the box is a rectangle, it is added as a rectangle if (cell.hasBorder(Rectangle.BOX)) { lines.rectangle(x1, y1, x2 - x1, y2 - y1); } // if the border isn't a rectangle, the different sides are added apart else { if (cell.hasBorder(Rectangle.RIGHT)) { lines.moveTo(x2, y1); lines.lineTo(x2, y2); } if (cell.hasBorder(Rectangle.LEFT)) { lines.moveTo(x1, y1); lines.lineTo(x1, y2); } if (cell.hasBorder(Rectangle.BOTTOM)) { lines.moveTo(x1, y2); lines.lineTo(x2, y2); } if (cell.hasBorder(Rectangle.TOP)) { lines.moveTo(x1, y1); lines.lineTo(x2, y1); } } lines.stroke(); if (color != null) { lines.resetRGBColorStroke(); } } }