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

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

Introduction

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

Prototype

public void concatenate(Matrix matrix) 

Source Link

Document

Concatenates (premultiplies) the given matrix to this matrix.

Usage

From source file:Bulletin.myPdf.java

public float TextCentered(String text, PDFont font, int size, float X, float Y, float rowHeight) {
    try {//  w  w  w  .j ava  2s  . co  m
        this.cos.beginText();
        this.cos.setFont(font, Math.round(textScale * size));
        float dtw = 0.5f * getTextWidth(font, text, size);
        float dth = 0.3f * getFontHeight(font, size);
        int nbLines = text.split("#").length;
        Y += 0.5f * (nbLines - 1) * rowHeight;

        for (String line : text.split("#")) {
            if (line.length() == 0) {
                continue;
            }
            //                System.out.println("X="+X+" Y="+Y);
            //                System.out.println("dtw="+dtw+" dth="+dth);
            Matrix M = Matrix.getTranslateInstance(X, Y);
            M.concatenate(Matrix.getRotateInstance(this.textAngle, 0, 0));
            M.concatenate(Matrix.getTranslateInstance(-dtw, -dth));

            this.cos.setTextMatrix(M);
            this.cos.showText(this.fix(line));
            //                this.cos.showText(new String(Base64.getDecoder().decode(line), "UTF-8"));

            Y -= rowHeight;
        }
        this.cos.endText();
        this.cos.stroke();

    } catch (IOException ex) {
        Logger.getLogger(Bulletin2.class.getName()).log(Level.SEVERE, null, ex);
    }
    return rowHeight;
}

From source file:Bulletin.myPdf.java

public float TextLeft(String text, PDFont font, int size, float X, float Y, float rowHeight) {
    try {//w  w  w  .j av  a 2  s .  com
        this.cos.beginText();
        this.cos.setFont(font, Math.round(textScale * size));
        float dth = 0.3f * getFontHeight(font, size);
        int nbLines = text.split("#").length;
        Y += 0.5f * (nbLines - 1) * rowHeight;

        for (String line : text.split("#")) {
            if (line.length() == 0) {
                continue;
            }
            //                System.out.println("X="+X+" Y="+Y);
            //                System.out.println("dtw="+dtw+" dth="+dth);
            Matrix M = Matrix.getTranslateInstance(X, Y);
            M.concatenate(Matrix.getRotateInstance(this.textAngle, 0, 0));
            M.concatenate(Matrix.getTranslateInstance(0, -dth));

            this.cos.setTextMatrix(M);
            this.cos.showText(this.fix(line));
            //                this.cos.showText(new String(Base64.getDecoder().decode(line), "UTF-8"));
            Y -= rowHeight;
        }
        this.cos.endText();
        this.cos.stroke();

    } catch (IOException ex) {
        Logger.getLogger(Bulletin2.class.getName()).log(Level.SEVERE, null, ex);
    }
    return rowHeight;
}

From source file:Bulletin.test.java

public static void test2() {
    try {/*from ww  w .  ja  va  2s  .co m*/
        PDDocument document = new PDDocument();
        PDPage page = new PDPage(PDRectangle.A4);
        PDPageContentStream cos = null;
        try {
            cos = new PDPageContentStream(document, page);
        } catch (IOException ex) {
            Logger.getLogger(test.class.getName()).log(Level.SEVERE, null, ex);
        }

        float X = 501.4f;
        float Y = 556.0f;
        //            String text = "HALLO";
        //            String text = "HALLO#HOE#GAAT#HET";
        //            String text = "HALLO#HOE#GAAT";
        String text = "Non atteints";
        int rh = 10;

        cos.moveTo(X, Y - 50);
        cos.lineTo(X, Y + 50);
        cos.stroke();
        cos.moveTo(X - 50, Y);
        cos.lineTo(X + 50, Y);
        cos.stroke();

        cos.beginText();
        cos.setFont(PDType1Font.HELVETICA, 6);
        float dtw = 0.5f * getTextWidth(PDType1Font.HELVETICA, text, 6);
        float dth = 0.0f * getFontHeight(PDType1Font.HELVETICA, 6);
        int nbLines = text.split("#").length;

        Y += 0.5f * (nbLines - 1) * rh;

        for (String line : text.split("#")) {
            Matrix M = Matrix.getTranslateInstance(X, Y);
            M.concatenate(Matrix.getRotateInstance(Math.toRadians(0), 0, 0));
            M.concatenate(Matrix.getTranslateInstance(-dtw, -dth));
            cos.setTextMatrix(M);
            cos.showText(line);
            Y -= rh;
        }
        cos.close();
        document.addPage(page);
        document.save("/tmp/test.pdf");
        document.close();

    } catch (IOException ex) {
        Logger.getLogger(test.class.getName()).log(Level.SEVERE, null, ex);
    }
}