Example usage for com.itextpdf.text.pdf PdfContentByte closePathFillStroke

List of usage examples for com.itextpdf.text.pdf PdfContentByte closePathFillStroke

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfContentByte closePathFillStroke.

Prototype


public void closePathFillStroke() 

Source Link

Document

Closes the path, fills it using the non-zero winding number rule to determine the region to fill and strokes it.

Usage

From source file:com.vectorprint.report.itext.EventHelper.java

License:Open Source License

/**
 * prints debug info when property debug is true, calls renderHeader and renderFooter and
 * {@link Advanced#draw(com.itextpdf.text.Rectangle, java.lang.String) } with {@link Document#getPageSize() }
 * and null for {@link DefaultStylerFactory#PAGESTYLERS}.
 *
 * @param writer//ww  w .j a va  2s.  c o m
 * @param document
 */
@Override
public final void onEndPage(PdfWriter writer, Document document) {
    super.onEndPage(writer, document);
    sanitize(writer);
    try {
        if (failuresHereAfter || debugHereAfter) {
            PdfContentByte bg = writer.getDirectContentUnder();
            Rectangle rect = writer.getPageSize();
            rect.setBackgroundColor(itextHelper
                    .fromColor(getSettings().getColorProperty(new Color(240, 240, 240), "legendbackground")));
            bg.rectangle(rect);
            bg.closePathFillStroke();
        } else {
            for (Advanced a : doForAllPages) {
                try {
                    if (a.shouldDraw(null)) {
                        a.draw(document.getPageSize(), null);
                    }
                } catch (VectorPrintException ex) {
                    throw new VectorPrintRuntimeException(ex);
                }
            }
        }
        if (!debugHereAfter && getSettings().getBooleanProperty(false, DEBUG)) {

            PdfContentByte canvas = writer.getDirectContent();

            Rectangle rect = new Rectangle(document.leftMargin(), document.bottomMargin(),
                    document.right() - document.rightMargin(), document.top() - document.topMargin());

            DebugHelper.debugRect(canvas, rect, new float[] { 10, 2 }, 0.3f, getSettings(),
                    stylerFactory.getLayerManager());

        }

        renderHeader(writer, document);
        maxTagForGenericTagOnPage = ((DefaultElementProducer) elementProducer).getAdvancedTag();
        if (getSettings().getBooleanProperty(Boolean.FALSE, ReportConstants.PRINTFOOTER)) {
            renderFooter(writer, document);
        } else {
            log.warning("not printing footer, if you want page footers set " + ReportConstants.PRINTFOOTER
                    + " to true");
        }
        maxTagForGenericTagOnPage = Integer.MAX_VALUE;
    } catch (VectorPrintException | DocumentException | InstantiationException | IllegalAccessException e) {
        throw new VectorPrintRuntimeException("failed to create the report header or footer: ", e);
    }
}

From source file:com.vectorprint.report.itext.style.stylers.Page.java

License:Open Source License

private void pageSettings() {
    if (getBackground() != null) {
        if (log.isLoggable(Level.FINE)) {
            log.fine("Possibly page background is written on top of page content making it invisible");
        }/*w w w  .  j  a  v  a 2s . c  o  m*/
        PdfContentByte bg = getWriter().getDirectContentUnder();
        Rectangle rect = getWriter().getPageSize();
        rect.setBackgroundColor(itextHelper.fromColor(getBackground()));
        bg.rectangle(rect);
        bg.closePathFillStroke();
    }
    getDocument().setPageSize(new Rectangle(getWidth(), getHeight()));
    getDocument().setMargins(getMargin_left(), getMargin_right(), getMargin_top(), getMargin_bottom());
}

From source file:com.vectorprint.report.itext.style.stylers.Shape.java

License:Open Source License

@Override
protected void draw(PdfContentByte canvas, float x, float y, float width, float height, String genericTag) {
    if (getBorderWidth() > 0) {
        canvas.setLineWidth(getBorderWidth());
        canvas.setColorStroke(itextHelper.fromColor((isDrawShadow()) ? getShadowColor() : getBorderColor()));
    }// w  ww .jav a2 s  .com
    if (width == -1) {
        width = getWidth();
    }
    if (height == -1) {
        height = getHeight();
    }
    canvas.setColorFill(itextHelper.fromColor((isDrawShadow()) ? getShadowColor() : getColor()));
    if (isRounded()) {
        canvas.setLineJoin(PdfContentByte.LINE_JOIN_ROUND);
    }
    float xx = x, yy = y;
    float[] points = getPoints();
    float padding = getPadding();
    switch (getShape()) {
    case free:
        float xdif = x - points[0];
        float ydif = y - points[1];
        xx = points[0] + xdif;
        yy = points[1] + ydif;
        canvas.moveTo(points[0] + xdif, points[1] + ydif);
        for (int i = 2; i < points.length; i = i + 2) {
            canvas.lineTo(points[i], points[i + 1]);
        }
        break;
    case bezier:
        xdif = x - points[0];
        ydif = y - points[1];
        xx = points[0] + xdif;
        yy = points[1] + ydif;
        canvas.moveTo(points[0] + xdif, points[1] + ydif);
        for (int i = 2; i < points.length; i = i + 4) {
            canvas.curveTo(points[i] + xdif, points[i + 1] + ydif, points[i + 2] + xdif, points[i + 3] + ydif);
        }
        break;
    case rectangle:
        if (isClose()) {
            xx = x - padding;
            yy = y - padding - height;
            canvas.rectangle(xx, yy, width + padding * 2, height + padding * 2);
        } else {
            canvas.rectangle(x, y, width, height);
        }
        break;
    case roundrectangle:
        if (isEnclosing()) {
            xx = x - padding;
            yy = y - padding - height;
            canvas.roundRectangle(xx, yy, width + padding * 2, height + padding * 2, getRadius());
        } else {
            canvas.roundRectangle(x, y, width, height, getRadius());
        }
        break;
    case ellipse:
        if (isEnclosing()) {
            xx = x - padding;
            yy = y - padding - height;
            canvas.ellipse(xx, yy, x + width + 2 * padding, y + 2 * padding);
        } else {
            canvas.ellipse(x, y, x + width, y + height);
        }
        break;
    }
    if (isClose()) {
        if (isFill()) {
            canvas.closePathFillStroke();
        } else {
            canvas.closePathStroke();
        }
    } else {
        canvas.stroke();
    }
    if (getSettings().getBooleanProperty(Boolean.FALSE, ReportConstants.DEBUG)) {
        DebugHelper.styleLink(canvas, getStyleClass(), " (styling)", xx, yy, getSettings(), getLayerManager());
    }
}

From source file:EplanPrinter.PDFPrint.java

License:Open Source License

public String insertStamp(String loc, float x, float y, int width, int height, int set, String date,
        int pageNum, int masterHeight, int masterWidth, String projNo)
        throws BadElementException, MalformedURLException, IOException, DocumentException {
    Image image = Image.getInstance(loc);
    float[] scalar = scale(x, y, width, height, masterHeight, masterWidth, pageNum);
    float[] trans = translate(x, y, r[pageNum - 1].getHeight(), r[pageNum - 1].getWidth(), masterHeight,
            masterWidth, pageNum);/*from w  ww . jav  a2s  .  co  m*/
    float[] f = commentTrans(x, y, masterHeight, masterWidth, pageNum);

    float shift = 0;

    /* Addition. ftorres - 7/22/2015 - Added to account for rotated pages 
     *   with the origin (0,0) not set to the bottom-left of the page. [1400] */
    trans = translateRotation(trans[0], trans[1], pageNum);

    if (set == 1) {
        float m = image.getPlainHeight();
        float pageChunk = r[pageNum - 1].getHeight() / 10;
        shift = r[pageNum - 1].getHeight() / 100;
        scalar[1] = (int) (pageChunk);
        scalar[0] = (int) (image.getPlainWidth() * pageChunk) / image.getPlainHeight();
        trans[0] = (int) (0 + (pageChunk * widthScalar));
        trans[1] = (int) (r[pageNum - 1].getHeight() - (pageChunk * heightScalar)
                - (shift * (heightScalar + 2)));
        heightScalar = heightScalar + 1;
        if (heightScalar == 8) {
            heightScalar = 0;
            widthScalar = widthScalar + 2;
        }
    }

    if (set == 1) {
        image.setAbsolutePosition(trans[0] + shift, trans[1] - scalar[1]);
        image.scaleAbsoluteHeight(scalar[1]);
        image.scaleAbsoluteWidth(scalar[0]);
        image.setRotationDegrees(rot);
    } else {
        //swap stamp dimensions for rotated drawings
        if (rot > 0) {
            image.setAbsolutePosition(trans[0] - 2 * scalar[1], trans[1] - 2 * scalar[0]);
        } else {
            image.setAbsolutePosition(trans[0], trans[1] - 2 * scalar[1]);
        }
        image.scaleAbsoluteHeight(scalar[1] * 2);
        image.scaleAbsoluteWidth(scalar[0] * 2);
        image.setRotationDegrees(rot);
    }

    PdfContentByte fg = pds.getOverContent(pageNum);
    fg.addImage(image);

    //Added by tmittelstadt on 09/21/2012 for ticket #698
    //draws a box around the date
    fg.setColorFill(BaseColor.WHITE);
    fg.setLineWidth(0f);

    //dmoody removed box.  ticket 900
    /*fg.moveTo(trans[0], trans[1] - scalar[1] * 2);
       fg.lineTo(trans[0], trans[1] - scalar[1] * 2 - 10);
       fg.lineTo(trans[0] + scalar[0] * 2, trans[1] - scalar[1] * 2 - 10);
       fg.lineTo(trans[0] + scalar[0] * 2, trans[1] - scalar[1] * 2);
       fg.lineTo(trans[0], trans[1] - scalar[1] * 2);*/

    fg.closePathFillStroke();
    fg.fill();

    //adds the date the stamp was added to the document to the pdf
    Phrase p = new Phrase(date);
    p.getFont().setColor(BaseColor.BLACK);
    //Modification zreeve 10/11/2012.  set font size to 11.
    p.getFont().setSize(9f);
    //p.getChunks().get(0).setAnnotation(PdfAnnotation.createText(pds.getWriter(), new Rectangle(trans[0],trans[1], trans[0]+5f, trans[1]+5f), id, comment, true, id));
    ColumnText.showTextAligned(fg, Element.ALIGN_CENTER, p, (float) (trans[0]),
            (float) (trans[1] - scalar[1] * 2 - 12), 0);
    Phrase pn = new Phrase("#[" + projNo + "]");
    pn.getFont().setColor(BaseColor.BLACK);
    pn.getFont().setSize(10f);
    pn.getFont().setStyle("bold");
    ColumnText.showTextAligned(fg, Element.ALIGN_CENTER, pn, (float) (trans[0]),
            (float) (trans[1] - scalar[1] * 2 - 22), 0);

    return "";
}

From source file:EplanPrinter.PDFPrint.java

License:Open Source License

public String insertSketch(String points, String color, String opac, int pageNum, int masterHeight,
        int masterWidth, int lineWeight, String lineStyle) throws DocumentException, IOException {
    float f = Float.valueOf(opac);
    PdfGState gs1 = new PdfGState();

    int t = points.indexOf("POLYGON");
    gs1.setFillOpacity(f);/*from w  w  w  .  ja  v  a  2 s  . c om*/

    PdfContentByte fg = pds.getOverContent(pageNum);
    fg.setGState(gs1);
    float[] pointsSt = shatterSketches(points);
    color = "0x" + color.substring(1);
    Color c = Color.decode(color);

    fg.setLineWidth(lineWeight * getRatio(masterHeight, masterWidth, pageNum));
    if (lineStyle.equals("dash")) {
        fg.setLineDash(lineWeight * 4f, lineWeight);
    } else {
        fg.setLineDash(0);
    }

    //fg.setLineWidth(5);
    fg.setColorStroke(new BaseColor(c.getRGB()));
    fg.setColorFill(new BaseColor(c.getRGB()));
    float[] prefl = scaleShape(pointsSt, masterHeight, masterWidth, pageNum);
    float[] fl = sketchTrans(prefl, pageNum);

    /* Addition. ftorres - 7/22/2015 - Added to account for rotated pages 
     *   with the origin (0,0) not set to the bottom-left of the page. [1400] */
    float flTrans[] = translateRotation(fl[0], fl[1], pageNum);

    if (points.indexOf("LINEPOINT") != -1) {
        fg.circle(flTrans[0], flTrans[1], 5);
        fg.fillStroke();
        if (t == -1) {
            gs1.setFillOpacity(0f);
        } else {
            gs1.setFillOpacity(f);
        }
        fg.setGState(gs1);
    }
    fg.moveTo(flTrans[0], flTrans[1]);
    for (int i = 2; i < pointsSt.length; i = i + 2) {
        flTrans = translateRotation(fl[i], fl[i + 1], pageNum);
        fg.lineTo(flTrans[0], flTrans[1]);
    }

    if (t != -1) {
        fg.closePathFillStroke();
        fg.fill();
    } else {
        fg.stroke();
    }

    return "";
}

From source file:EplanPrinter.PDFPrint.java

License:Open Source License

public String insertComment(String sx, String sy, String id, String deptValue, String userInit, String comment,
        int pageNum, int masterHeight, int masterWidth, int pinned, int customFontSize)
        throws DocumentException, IOException {
    float ratio = getRatio(masterHeight, masterWidth, pageNum);
    float x = Float.parseFloat(sx);
    float y = Float.parseFloat(sy);
    float[] f = commentTrans(x, y, masterHeight, masterWidth, pageNum);
    PdfGState gs1 = new PdfGState();
    gs1.setFillOpacity(1);//from   w  w  w . j a  v  a 2  s . co  m
    if (customFontSize > 0)
        fontSize = customFontSize;

    PdfContentByte fg = pds.getOverContent(pageNum);
    fg.setGState(gs1);
    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
    float[] trans = translate(x, y, r[pageNum - 1].getHeight(), r[pageNum - 1].getWidth(), masterHeight,
            masterWidth, pageNum);
    // comment tag image (width=35pts, height=8pts)
    float[] scalar = scale(trans[0], trans[1], 35, 8, masterHeight, masterWidth, pageNum);

    /* Addition. ftorres - 7/21/2015 - Added to account for rotated pages 
     *   with the origin (0,0) not set to the bottom-left of the page. [1400] */
    float coords[] = translateRotation(trans[0], trans[1], pageNum);
    coords = checkBounds(coords[0], coords[1], pageNum);

    /* Addition. ftorres - 10/20/2015 - If the comment was pinned in EPC, then
     *   render the comment inside a comment box. */
    if (pinned == 1) {
        insertPinnedComment(coords[0], coords[1], id + " - " + deptValue + " (" + userInit + ")", comment,
                pageNum, masterHeight, masterWidth);

        // Add the pinned comment text to page annotation -Jon Changkachith 11/24/2015
        Rectangle rect = new Rectangle(0, 0, 0, 0);
        PdfAnnotation annotation = PdfAnnotation.createText(pds.getWriter(), rect,
                id + " - " + deptValue + " (" + userInit + ")", cleanupComment(comment), true, id);
        pds.addAnnotation(annotation, pds.getWriter().getCurrentPageNumber());
    } else {
        Image image = Image.getInstance(commentIMGPath);
        image.setAbsolutePosition(coords[0] + (scalar[0] * (id.length() / 5f)), coords[1]);

        /*
         * Commented out by Jon Changkachith 12/09/2015 because it was throwing
         * DocumentException with the message "The image must have absolute positioning."
        image.scaleAbsoluteHeight(1);
        image.scaleAbsoluteWidth(1);
        */
        image.scalePercent(ratio); //Added to fix DocumentException "The image must have absolute positioning." Jon Changkachith 12/09/2015
        image.setAnnotation(new Annotation(id + " - " + deptValue + " (" + userInit + ")",
                cleanupComment(comment), 0, 0, 0, 0));
        fg.addImage(image);
    }

    fg.setLineWidth(.5f * ratio);
    fg.setColorStroke(new BaseColor(Color.decode("0x6E2405").getRGB()));
    fg.setColorFill(new BaseColor(Color.decode("0x6E2405").getRGB()));

    float tHeight = scalar[1];
    float tWidth = 0;
    if (id.length() > 3) {
        tWidth = (scalar[0] * (id.length() / 5f));
    } else {
        tWidth = (scalar[0]);
    }

    fg.moveTo(coords[0], coords[1]);
    fg.lineTo(coords[0] + (10f * ratio), coords[1] - (tHeight / 2));
    fg.lineTo(coords[0] + tWidth, coords[1] - (tHeight / 2));
    fg.lineTo(coords[0] + tWidth, coords[1] + (tHeight / 2));
    fg.lineTo(coords[0] + (10f * ratio), coords[1] + (tHeight / 2));

    fg.lineTo(coords[0], coords[1]);
    fg.closePathFillStroke();
    fg.fill();

    // Comment number that goes on the comment tag image
    Phrase p = new Phrase(id);
    p.getFont().setColor(BaseColor.WHITE);
    p.getFont().setSize(8f * ratio); //comment number font size = 8f
    //p.getChunks().get(0).setAnnotation(PdfAnnotation.createText(pds.getWriter(), new Rectangle(trans[0],trans[1], trans[0]+5f, trans[1]+5f), id, comment, true, id));

    float fs[] = translateRotation(f[0], f[1], pageNum);
    fs = checkBounds(fs[0], fs[1], pageNum);
    ColumnText.showTextAligned(fg, Element.ALIGN_LEFT, p, (float) (fs[0] + (9 * ratio)),
            (float) (fs[1] - (3 * ratio)), 0);

    return "";
}