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

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

Introduction

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

Prototype


public void stroke() 

Source Link

Document

Strokes the path.

Usage

From source file:se.billes.pdf.renderer.model.Line.java

License:Open Source License

@Override
public void onRender(PdfContentByte cb) throws PdfRenderException {

    Integer[] pageSizes = getPage().getPdfDocument().getSize();
    float[] pos = getPosition();
    float[] moveTo = getMoveTo();
    cb.setLineWidth(getThickness());/*from ww w . j a v a 2  s .  c o m*/
    cb.setColorStroke(getBaseColor());
    float y1 = pageSizes[1] + SizeFactory.CUT_MARK - pos[1]; // seams strange but pdf starts bottom and up.
    float y2 = pageSizes[1] + SizeFactory.CUT_MARK - moveTo[1];
    // x , y. y is backward in pdf so start pos is the entire page height
    cb.moveTo(SizeFactory.millimetersToPostscriptPoints(pos[0] + SizeFactory.CUT_MARK),
            SizeFactory.millimetersToPostscriptPoints(y1));
    cb.lineTo(SizeFactory.millimetersToPostscriptPoints(moveTo[0] + SizeFactory.CUT_MARK),
            SizeFactory.millimetersToPostscriptPoints(y2));
    cb.stroke();

}

From source file:se.billes.pdf.renderer.process.CutmarksRenderer.java

License:Open Source License

public void render(PdfWriter writer, Document document) {

    Cutmarks cutmarks = request.getCutmarks();
    if (cutmarks != null && !cutmarks.isIgnoreCutStroke()) {

        float width = SizeFactory.CUT_MARK;
        float height = SizeFactory.CUT_MARK;
        float lineWidth = SizeFactory.CUT_MARK_LINE;
        float lineHeight = SizeFactory.CUT_MARK_LINE;
        Rectangle rect = document.getPageSize();
        PdfContentByte cb = writer.getDirectContent();
        cb.setLineWidth(0.1f);/*from  w  ww . ja v a  2 s. c  o  m*/

        cb.moveTo(SizeFactory.millimetersToPostscriptPoints(width), 0);
        cb.lineTo(SizeFactory.millimetersToPostscriptPoints(width),
                SizeFactory.millimetersToPostscriptPoints(lineHeight));
        cb.stroke();

        cb.moveTo(0, SizeFactory.millimetersToPostscriptPoints(height));
        cb.lineTo(SizeFactory.millimetersToPostscriptPoints(lineWidth),
                SizeFactory.millimetersToPostscriptPoints(height));
        cb.stroke();

        // Upper left cut mark
        cb.moveTo(SizeFactory.millimetersToPostscriptPoints(width), rect.getHeight());
        cb.lineTo(SizeFactory.millimetersToPostscriptPoints(width),
                rect.getHeight() - SizeFactory.millimetersToPostscriptPoints(lineHeight));
        cb.stroke();

        cb.moveTo(0, rect.getHeight() - SizeFactory.millimetersToPostscriptPoints(height));
        cb.lineTo(SizeFactory.millimetersToPostscriptPoints(lineWidth),
                rect.getHeight() - SizeFactory.millimetersToPostscriptPoints(height));
        cb.stroke();

        /**
         * Upper right cut mark
         */
        cb.moveTo(rect.getWidth(), rect.getHeight() - SizeFactory.millimetersToPostscriptPoints(height));
        cb.lineTo(rect.getWidth() - SizeFactory.millimetersToPostscriptPoints(lineWidth),
                rect.getHeight() - SizeFactory.millimetersToPostscriptPoints(height));
        cb.stroke();
        cb.moveTo(rect.getWidth() - SizeFactory.millimetersToPostscriptPoints(width), rect.getHeight());
        cb.lineTo(rect.getWidth() - SizeFactory.millimetersToPostscriptPoints(width),
                rect.getHeight() - SizeFactory.millimetersToPostscriptPoints(lineHeight));
        cb.stroke();

        /**
         * Lower right cut mark
         */
        cb.moveTo(rect.getWidth() - SizeFactory.millimetersToPostscriptPoints(width), 0);
        cb.lineTo(rect.getWidth() - SizeFactory.millimetersToPostscriptPoints(width),
                SizeFactory.millimetersToPostscriptPoints(lineHeight));
        cb.stroke();

        cb.moveTo(rect.getWidth(), SizeFactory.millimetersToPostscriptPoints(height));
        cb.lineTo(rect.getWidth() - SizeFactory.millimetersToPostscriptPoints(lineWidth),
                SizeFactory.millimetersToPostscriptPoints(height));
        cb.stroke();
    }
}

From source file:se.inera.intyg.intygstyper.fk7263.pdf.PdfAbstractGenerator.java

License:Open Source License

protected void mark(PdfStamper pdfStamper, String watermarkText, int startX, int startY, int height, int width)
        throws DocumentException, IOException {
    PdfContentByte addOverlay;
    addOverlay = pdfStamper.getOverContent(1);
    addOverlay.saveState();//from   w  w  w . ja v  a  2s . com
    addOverlay.setColorFill(CMYKColor.WHITE);
    addOverlay.setColorStroke(CMYKColor.RED);
    addOverlay.rectangle(startX, startY, width, height);
    addOverlay.stroke();
    addOverlay.restoreState();

    // Do text
    addOverlay = pdfStamper.getOverContent(1);
    ColumnText ct = new ColumnText(addOverlay);
    BaseFont bf = BaseFont.createFont();
    Font font = new Font(bf, WATERMARK_FONTSIZE);
    int llx = startX + WATERMARK_TEXT_PADDING;
    int lly = startY + WATERMARK_TEXT_PADDING;
    int urx = llx + width - 2 * WATERMARK_TEXT_PADDING;
    int ury = lly + height - 2 * WATERMARK_TEXT_PADDING;
    Phrase phrase = new Phrase(watermarkText, font);
    ct.setSimpleColumn(phrase, llx, lly, urx, ury, WATERMARK_FONTSIZE, Element.ALIGN_LEFT | Element.ALIGN_TOP);
    ct.go();
}