Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I cannot understand what the 6 values that go in the matrix m 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.
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.

Maybe go read the explanation of AffineTransform in the java documentation, this is the same except that the parameters are different. See also the static methods of Matrix.* – Tilman Hausherr Sep 20, 2016 at 16:31 scaleXm00 shearYm10 shearXm01 scaleYm11 transXm02 transYm12 - it is confusing because Adobe uses another ordering than java. – Tilman Hausherr Sep 21, 2016 at 9:01

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.

You'e just telling me about the data types, you aren't telling me what is the a value, what is the b value etc. Are these the x/y coordinates, or translations etc – Yuganka Sharan Sep 23, 2016 at 7:24 @Yuganka do you know Linear Algebra? In particular how translations, rotations, etc. can be mathematically be expressed as affine transformations, and how by embedding the two dimensional plane in the three dimensional space you can model the affine transformations of the plane by means of a sub set of the 3x3 matrices? In computer graphics you usually are expected to know some basic mathematics. – mkl Sep 24, 2016 at 6:33

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.