Yuganka Sharan - 11 months ago 56

Android Question

I cannot understand what the 6 values that go in the matrix

`m`

`PDPageContentStream.setTextMatrix(Matrix m)`

Yes I have read the docs and I found the explanation completely useless -

`public void setTextMatrix(double a,`

double b,

double c,

double d,

double e,

double f)

throws IOException

The Tm operator. Sets the text matrix to the given values. A current text matrix will be replaced with the new one.

Parameters:

a - The a value of the matrix.

b - The b value of the matrix.

c - The c value of the matrix.

d - The d value of the matrix.

e - The e value of the matrix.

f - The f value of the matrix.

I have also searched for examples, but nowhere did I find an explanation of these values. Also, strangely, when I tried the same values with 2 different PDF files, the results were different so I'm assuming this has something to do with margins and distances etc.

I feel I am wasting my time in doing guess work. A direct explanation of the arguments will be really good.

I know about the matrix and how to pass values. I don't know what the values in the matrix actually mean.

Answer Source

You could try bypassing the new method requirement, by using one of the `Matrix`

constructors

```
setTextMatrix(new Matrix(Double.valueOf(a).floatValue(),
Double.valueOf(b).floatValue(),
Double.valueOf(c).floatValue(),
Double.valueOf(d).floatValue(),
Double.valueOf(e).floatValue(),
Double.valueOf(f).floatValue()))
```

with the small risk of losing some of the `double`

accuracy.

**EDIT:**

You could check out this example - UsingTextMatrix.

**Per PDPageContentStream.java** this is the deprecated `setTextMethod`

, for which you inquired:

```
@Deprecated
public void setTextMatrix(double a, double b, double c, double d, double e, double f) throws IOException
{
setTextMatrix(new Matrix((float)a, (float)b, (float)c, (float)d, (float)e, (float)f));
}
```

which basically does what I tried above. So there shouldn't be any major differences, outside more compact usage. For more information the `org.apache.pdfbox.pdmodel.PDPageContentStream`

class.

Regarding the meaning of the single float/double values:

`a, b, c, d, e, f`

define a single `org.apache.pdfbox.cos.COSArray`

of the form:

```
static final float[] DEFAULT_SINGLE =
{
a,b,0,
c,d,0,
e,f,1
};
```

where

```
a stands for ScaleX
b stands for ShearY
c stands for ShearX
d stands for ScaleY
e stands for TranslateX
f stands for TranslateY
```

Here in this Wiki about Affine Transformations you could read what you could do with these values. And below are visually represented the possible operations:

Note: There is a slight difference in the position of `tX`

and `tY`

in the `org.apache.pdfbox.util.Matrix`

and the image above.

Hopes this clears out the issue.