Search in sources :

Example 1 with CellRenderer

use of com.itextpdf.layout.renderer.CellRenderer in project i7js-highlevel by itext.

the class AlternatingBackgroundTableRenderer method draw.

@Override
public void draw(DrawContext drawContext) {
    for (int i = 0; i < rows.size() && null != rows.get(i) && null != rows.get(i)[0]; i++) {
        CellRenderer[] renderers = rows.get(i);
        Rectangle leftCell = renderers[0].getOccupiedAreaBBox();
        Rectangle rightCell = renderers[renderers.length - 1].getOccupiedAreaBBox();
        Rectangle rect = new Rectangle(leftCell.getLeft(), leftCell.getBottom(), rightCell.getRight() - leftCell.getLeft(), leftCell.getHeight());
        PdfCanvas canvas = drawContext.getCanvas();
        canvas.saveState();
        if (isOdd) {
            canvas.setFillColor(ColorConstants.LIGHT_GRAY);
            isOdd = false;
        } else {
            canvas.setFillColor(ColorConstants.YELLOW);
            isOdd = true;
        }
        canvas.rectangle(rect);
        canvas.fill();
        canvas.restoreState();
    }
    super.draw(drawContext);
}
Also used : Rectangle(com.itextpdf.kernel.geom.Rectangle) PdfCanvas(com.itextpdf.kernel.pdf.canvas.PdfCanvas) CellRenderer(com.itextpdf.layout.renderer.CellRenderer)

Aggregations

Rectangle (com.itextpdf.kernel.geom.Rectangle)1 PdfCanvas (com.itextpdf.kernel.pdf.canvas.PdfCanvas)1 CellRenderer (com.itextpdf.layout.renderer.CellRenderer)1