Example usage for com.itextpdf.text.pdf PdfTemplate setColorFill

List of usage examples for com.itextpdf.text.pdf PdfTemplate setColorFill

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfTemplate setColorFill.

Prototype

public void setColorFill(final BaseColor color) 

Source Link

Document

Sets the fill color.

Usage

From source file:se.billes.pdf.renderer.request.factory.CellBlockEvent.java

License:Open Source License

public PdfPCellEvent createEvent(final Block block) {
    return new PdfPCellEvent() {
        public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvas) {

            float radiusInPs = SizeFactory.millimetersToPostscriptPoints(block.getRadius());
            PdfContentByte cb = canvas[PdfPTable.LINECANVAS];
            PdfTemplate template = cb.createTemplate(rect.getWidth(), rect.getHeight());
            template.roundRectangle(0, 0, rect.getWidth(), rect.getHeight(), radiusInPs);
            template.clip();/*from  w  ww.j a  va  2s.  com*/
            template.newPath();

            if (block.getBaseColor() != null) {
                template.setColorFill(block.getBaseColor());
            }

            Border border = block.getBorder();

            if (border != null) {
                template.setLineWidth(SizeFactory.millimetersToPostscriptPoints(border.getThickness()));
                template.setColorStroke(border.getBaseColor());
            }

            template.roundRectangle(0, 0, rect.getWidth(), rect.getHeight(), radiusInPs);

            if (block.getBaseColor() != null || border != null) {
                if (block.getBaseColor() != null && border != null) {
                    template.fillStroke();
                } else if (block.getBaseColor() != null) {
                    template.fill();
                } else {

                    template.stroke();
                }
            }
            cb.addTemplate(template, rect.getLeft(), rect.getBottom());
        }
    };
}