Example usage for org.apache.pdfbox.util Matrix Matrix

List of usage examples for org.apache.pdfbox.util Matrix Matrix

Introduction

In this page you can find the example usage for org.apache.pdfbox.util Matrix Matrix.

Prototype

public Matrix(AffineTransform at) 

Source Link

Document

Creates a matrix with the same elements as the given AffineTransform.

Usage

From source file:de.rototor.pdfbox.graphics2d.PdfBoxGraphics2D.java

License:Apache License

public boolean drawImage(Image img, AffineTransform xform, ImageObserver obs) {
    checkNoCopyActive();/*w w  w  .  j a  v  a  2s .  c om*/
    AffineTransform tf = new AffineTransform();
    tf.concatenate(baseTransform);
    tf.concatenate(transform);

    // Sometimes the xform can be null
    if (xform != null)
        tf.concatenate((AffineTransform) xform.clone());

    PDImageXObject pdImage = imageEncoder.encodeImage(document, contentStream, img);
    try {
        contentStreamSaveState();
        int imgHeight = img.getHeight(obs);
        tf.translate(0, imgHeight);
        tf.scale(1, -1);
        contentStream.transform(new Matrix(tf));

        Object keyInterpolation = renderingHints.get(RenderingHints.KEY_INTERPOLATION);
        if (RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR.equals(keyInterpolation))
            pdImage.setInterpolate(false);
        contentStream.drawImage(pdImage, 0, 0, img.getWidth(obs), imgHeight);
        contentStreamRestoreState();
    } catch (IOException e) {
        throwException(e);
    }
    return true;
}

From source file:de.rototor.pdfbox.graphics2d.PdfBoxGraphics2D.java

License:Apache License

private void drawStringUsingText(AttributedCharacterIterator iterator, float x, float y)
        throws IOException, FontFormatException {
    contentStreamSaveState();//from   w ww. ja  va2  s . com

    AffineTransform tf = new AffineTransform(baseTransform);
    tf.concatenate(transform);
    tf.translate(x, y);
    contentStream.transform(new Matrix(tf));

    fontTextDrawer.drawText(iterator, fontDrawerEnv);

    contentStreamRestoreState();
}