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

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

Introduction

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

Prototype


public void lineTo(final double x, final double y) 

Source Link

Document

Appends a straight line segment from the current point (x, y).

Usage

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()));
    }/*from  ww  w  . j  av  a 2s  .  co  m*/
    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:com.vectorprint.report.itext.style.stylers.Underline.java

License:Open Source License

@Override
public void draw(Rectangle rect, String genericTag) throws VectorPrintException {
    if (genericTag == null) {
        if (log.isLoggable(Level.FINE)) {
            log.fine("not drawing underline because genericTag is null (no data for underline)");
        }/*from   w ww . j  a va 2 s  .  co m*/
        return;
    }
    DelayedData delayed = getDelayed(genericTag);
    PdfContentByte canvas = getPreparedCanvas();
    try {
        com.itextpdf.text.Font f = delayed.getChunk().getFont();
        canvas.setColorStroke((getColor() == null) ? f.getColor() : itextHelper.fromColor(getColor()));
        canvas.setLineWidth(getLineWidth());
        if (delayed.getChunk().getTextRise() != 0) {
            canvas.transform(AffineTransform.getTranslateInstance(0, delayed.getChunk().getTextRise()));
        }
        HashMap<String, Object> attributes = delayed.getChunk().getAttributes();
        if (attributes != null && attributes.containsKey(Chunk.SKEW)) {
            log.warning("lines under skewed text may not be at the correct position");
        }
        canvas.moveTo(rect.getLeft(), rect.getBottom());
        canvas.lineTo(rect.getLeft() + rect.getWidth(), rect.getBottom());
        canvas.stroke();
    } catch (Exception ex) {
        resetCanvas(canvas);
        throw new VectorPrintException(ex);
    }
    resetCanvas(canvas);
}

From source file:de.jost_net.JVerein.io.HeaderFooter.java

License:Open Source License

/**
 * Adds the header and the footer.//  w w  w.j  ava  2 s.  co  m
 * 
 */
@Override
public void onEndPage(PdfWriter writer, Document document) {
    Rectangle rect = document.getPageSize();
    switch (writer.getPageNumber() % 2) {
    case 0:
        // ColumnText.showTextAligned(writer.getDirectContent(),
        // Element.ALIGN_RIGHT, header[0], rect.getRight(), rect.getTop(), 0);
        break;
    case 1:
        // ColumnText.showTextAligned(writer.getDirectContent(),
        // Element.ALIGN_LEFT,
        // header[1], rect.getLeft(), rect.getTop(), 0);
        break;
    }
    float left = rect.getLeft() + document.leftMargin();
    float right = rect.getRight() - document.rightMargin();
    float bottom = rect.getBottom() + document.bottomMargin();
    PdfContentByte pc = writer.getDirectContent();
    pc.setColorStroke(BaseColor.BLACK);
    pc.setLineWidth(0.5f);
    pc.moveTo(left, bottom - 5);
    pc.lineTo(right, bottom - 5);
    pc.stroke();
    pc.moveTo(left, bottom - 25);
    pc.lineTo(right, bottom - 25);
    pc.stroke();

    ColumnText.showTextAligned(pc, Element.ALIGN_CENTER,
            new Phrase(footer + " " + pagenumber, Reporter.getFreeSans(7)), (left + right) / 2, bottom - 18, 0);
}

From source file:engine.Pdf.java

public static void drawLines(Vector<HoughLine> vectors, PdfWriter writer) {
    PdfContentByte canvas = writer.getDirectContent();
    canvas.setColorStroke(BaseColor.RED);
    canvas.setLineWidth(1);/*  w  w  w.  ja va 2  s .  c o m*/
    for (int i = 0; i < vectors.size(); i++) {
        HoughLine line = vectors.elementAt(i);
        canvas.moveTo(line.x1, line.y1);
        canvas.lineTo(line.x2, line.y2);
        canvas.closePathStroke();
    }
    //        canvas.closePathStroke();
    canvas.setColorFill(BaseColor.BLUE);
    canvas.fill();
}

From source file:engine.Pdf.java

public static void drawLines(PdfWriter writer) {
    PdfContentByte canvas = writer.getDirectContent();
    canvas.setColorStroke(BaseColor.RED);
    canvas.setLineWidth(3);/*from w w  w .j a va2s . co m*/
    canvas.moveTo(20, 30);
    canvas.lineTo(900, 900);
    canvas.lineTo(220, 330);
    canvas.closePathStroke();
    canvas.setColorFill(BaseColor.RED);
    canvas.fill();
}

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.j  av a2s  . c o  m*/

    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   ww w.  j  av  a  2 s.c  o  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 "";
}

From source file:es.clinica.veterinaria.facturas.FacturaPdf.java

private void generateHeader(Document doc, PdfContentByte cb) {
    try {/*w w w  . jav  a  2s  .  co  m*/

        createHeadings(cb, 150, 790, "Centro Veterinario \"Mascotas\"", 10);
        createHeadings(cb, 150, 775, "Nombre del profesional", 8);
        createHeadings(cb, 150, 760, "NIF: 11.111.111-A", 8);
        createHeadings(cb, 150, 745, "C/ Nombre de la calles, 1", 8);
        createHeadings(cb, 150, 730, "Nombre de la Ciudad (Provincia)", 8);
        createHeadings(cb, 150, 715, "Telfono: 600 00 00 00", 8);

        cb.setLineWidth(1f);

        // Invoice Header box layout
        //            cb.rectangle(70,600,150,60);
        cb.roundRectangle(460, 770, 100, 50, 5); //x, y, ancho, alto, round
        cb.roundRectangle(460, 705, 100, 50, 5); //x, y, ancho, alto, round
        cb.moveTo(460, 797); // (x,y)
        cb.lineTo(560, 797);
        cb.moveTo(460, 732);
        cb.lineTo(560, 732);
        cb.stroke();

        createHeadings(cb, 480, 804, "FACTURA", 12);
        createHeadings(cb, 502, 780, "" + factura.getNumero(), 14);
        createHeadings(cb, 488, 739, "FECHA", 12);
        createHeadings(cb, 470, 715, new SimpleDateFormat("dd / MM / yyyy").format(factura.getFecha()), 14);

        cb.setLineWidth(1f);
        cb.roundRectangle(25, 565, 540, 120, 5); //x, y, ancho, alto, round
        cb.stroke();

        //            cb.setGrayStroke(1f);
        //            cb.rectangle(25, 665, 299, 20); //x,y, ancho, alto

        //            cb.setGrayStroke(20f);
        cb.moveTo(25, 660); // (x,y)
        cb.lineTo(565, 660);
        cb.stroke();

        createHeadings(cb, 265, 667, "CLIENTE", 12);
        createCliente(cb, 35, 643, "Nombre:    " + factura.getCliente().getFullname(), 11);
        createCliente(cb, 35, 626, "NIF/CIF:    " + factura.getCliente().getNif(), 11);
        createCliente(cb, 35, 608, "Direccin:  " + factura.getCliente().getDireccion(), 11);
        createCliente(cb, 35, 590,
                "Ciudad:     " + factura.getCliente().getCiudad().getPoblacion() + ", "
                        + factura.getCliente().getCodigopostal() + ",  ("
                        + factura.getCliente().getProvincia().getProvincia() + ")",
                11);
        createCliente(cb, 35, 572, "Telfono:   " + factura.getCliente().getTelefono(), 11);

    } catch (Exception ex) {
        ex.printStackTrace();
    }

}

From source file:gov.utah.dts.det.ccl.actions.facility.information.license.reports.LicenseCertificate.java

private static void showPageMarginBorders(PdfContentByte canvas) {
    canvas.moveTo(LEFT_MARGIN, TOP_MARGIN);
    canvas.lineTo(LEFT_MARGIN, BOTTOM_MARGIN);
    canvas.lineTo(RIGHT_MARGIN, BOTTOM_MARGIN);
    canvas.lineTo(RIGHT_MARGIN, TOP_MARGIN);
    canvas.lineTo(LEFT_MARGIN, TOP_MARGIN);
    canvas.stroke();//from ww  w . j  a  v  a  2  s  . co  m
}

From source file:gov.utah.dts.det.ccl.actions.facility.information.license.reports.LicenseCertificate.java

private static void showColumnBorders(PdfContentByte canvas) {
    for (int i = 0; i < COLUMNS.length; i++) {
        canvas.moveTo(COLUMNS[i][0], COLUMNS[i][1]);
        canvas.lineTo(COLUMNS[i][2], COLUMNS[i][1]);
        canvas.lineTo(COLUMNS[i][2], COLUMNS[i][3]);
        canvas.lineTo(COLUMNS[i][0], COLUMNS[i][3]);
        canvas.lineTo(COLUMNS[i][0], COLUMNS[i][1]);
        canvas.stroke();/*from   w  w w .  ja  v  a2s .c  o m*/
    }
}