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

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

Introduction

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

Prototype

public void setTextMatrix(final float a, final float b, final float c, final float d, final float x,
        final float y) 

Source Link

Document

Changes the text matrix.

Usage

From source file:com.vectorprint.report.itext.style.stylers.Shadow.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 shadow because genericTag is null (no data for shadow)");
        }//from   w  w w. j a v  a 2  s  .co m
        return;
    }
    DelayedData delayed = getDelayed(genericTag);
    PdfContentByte canvas = getPreparedCanvas();
    try {
        com.itextpdf.text.Font f = delayed.getChunk().getFont();
        if (f.getBaseFont() == null) {
            throw new VectorPrintRuntimeException(
                    "font " + f.getFamilyname() + " does not have a basefont, check your fontloading");
        }
        /*
         * print as much of the text as fits in the width of the rectangle
         */
        String toPrint = delayed.getStringData();
        int i = toPrint.length() + 1;
        do {
            toPrint = toPrint.substring(0, --i);
        } while (ItextHelper.getTextWidth(toPrint, f.getBaseFont(), f.getSize()) > rect.getWidth() + 1);
        if (i < delayed.getStringData().length()) {
            String nextPart = delayed.getStringData().substring(i).replaceFirst(" *", "");
            if (log.isLoggable(Level.FINE)) {
                log.fine(String.format("event %s, printed shadow %s of %s, left %s for next event", genericTag,
                        toPrint, delayed.getData(), nextPart));
            }
            delayed.setData(nextPart);
        }

        canvas.setFontAndSize(f.getBaseFont(), f.getSize());
        canvas.setColorFill((getColor() == null) ? f.getColor() : itextHelper.fromColor(getColor()));
        canvas.setColorStroke((getColor() == null) ? f.getColor() : itextHelper.fromColor(getColor()));

        canvas.beginText();
        HashMap<String, Object> attributes = delayed.getChunk().getAttributes();
        if (attributes != null && attributes.containsKey(Chunk.SKEW)) {
            float[] skew = (float[]) attributes.get(Chunk.SKEW);
            canvas.setTextMatrix(1, skew[0], skew[1], 1, rect.getLeft() + calculateShift(getShiftx(), f),
                    rect.getBottom() - calculateShift(getShifty(), f));
        } else {
            canvas.setTextMatrix(1, 0, 0, 1, rect.getLeft() + calculateShift(getShiftx(), f),
                    rect.getBottom() - calculateShift(getShifty(), f));
        }
        canvas.setTextRise(delayed.getChunk().getTextRise());
        canvas.showText(toPrint);
        canvas.endText();
    } catch (Exception ex) {
        resetCanvas(canvas);
        throw new VectorPrintException(ex);
    }
    resetCanvas(canvas);
}

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

License:Open Source License

protected void createRightMarginText(PdfStamper pdfStamper, int numberOfPages, String id, String text)
        throws DocumentException, IOException {
    PdfContentByte addOverlay;
    BaseFont bf = BaseFont.createFont();
    // Do text// ww w .  j  av a2  s.  co  m
    for (int i = 1; i <= numberOfPages; i++) {
        addOverlay = pdfStamper.getOverContent(i);
        addOverlay.saveState();
        addOverlay.beginText();
        addOverlay.setFontAndSize(bf, MARGIN_TEXT_FONTSIZE);
        addOverlay.setTextMatrix(0, 1, -1, 0, MARGIN_TEXT_START_X, MARGIN_TEXT_START_Y);
        addOverlay.showText(String.format("Intygs-ID: %s. %s", id, text));
        addOverlay.endText();
        addOverlay.restoreState();
    }
}

From source file:se.inera.intyg.intygstyper.ts_bas.pdf.PdfGeneratorImpl.java

License:Open Source License

private void createLeftMarginText(PdfStamper pdfStamper, int numberOfPages, String id, String text)
        throws DocumentException, IOException {
    PdfContentByte addOverlay;
    BaseFont bf = BaseFont.createFont();
    // Do text/* w  w  w.j  ava 2  s  .co m*/
    for (int i = 1; i <= numberOfPages; i++) {
        addOverlay = pdfStamper.getOverContent(i);
        addOverlay.saveState();
        addOverlay.beginText();
        addOverlay.setFontAndSize(bf, MARGIN_TEXT_FONTSIZE);
        addOverlay.setTextMatrix(0, 1, -1, 0, MARGIN_TEXT_START_X, MARGIN_TEXT_START_Y);
        addOverlay.showText(String.format("Intygs-ID: %s. %s", id, text));
        addOverlay.endText();
        addOverlay.restoreState();
    }
}