Yuganka Sharan Yuganka Sharan - 2 months ago 6
Android Question

Understanding the arguments of PDPageContentStream.setTextMatrix()

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

of the argument of
PDPageContentStream.setTextMatrix(Matrix m)
denote. Earlier it used to take 6 values, but now it takes a single matrix containing all the values.

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.

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.


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

setTextMatrix(new Matrix(Double.valueOf(a).floatValue(),

with the small risk of losing some of the double accuracy.

You could check out this example - UsingTextMatrix.

Per PDPageContentStream.java this is the deprecated setTextMethod, for which you inquired:

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 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: enter image description here

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.