# What are "a" and "d" parameter in SetTextMatrix(a..d..) or SetTransofrm(a..d..)?

Q:
When writing text into a PDF I need to specify the Textmatrix like
this:

element.SetTextMatrix(a, b, c, d, h, v);

What do "a" and "d" do? It seems the larger the values I chosen, the
bigger are the letters. But the letters should be only defined by one
value. E.g.12pt
---

A:

'a,b,c,d,h,v' are used to represent PDF transformation matrix (see
sections 4.2 'Coordinate Systems' and 4.2.3 'Transformation Matrices'
in PDF Reference Manual).

'a' and 'd' are usually used to represent horizontal and vertical
scaling respectively.

The following are examples of most common transformations:
---------------------------
- Translations are specified as [1 0 0 1 tx ty], where tx and ty are
the distances to translate the origin of the coordinate system in the
horizontal and vertical dimensions, respectively.

- Scaling is obtained by [sx 0 0 sy 0 0]. This scales the
coordinates so that 1 unit in the horizontal and vertical dimensions
of the new coordinate system is the same size as sx and sy units,
respectively, in the previous coordinate system.

- Rotations are produced by [cos(A) sin(A) -sin(A) cos(A) 0 0],
which has the effect of rotating the coordinate system axes by an
angle 'A' counterclockwise.

- Skew is specified by [1 tan(A) tan(B) 1 0 0], which skews the x
axis by an angle A and the y axis by an angle B.
---------------------------

If you know the positioning information as a rectangle on the page you
can create text matrix as follows:

element.SetTextMatrix(rect.Width(), 0, 0, rect.Height(), rect.x1,
rect.y1);

where (rect.x1, rect.y1) is the lower-left coordinate of the
positioning rectangle and rect.Width()/Height() are the dimensions of
the element bounding box.

Please keep in mind that in this case you should keep font size to 1
(otherwise the dimensions of the text box will be multiplied by font
size):

Element element = eb.CreateTextBegin(font, 1);
element.SetTextMatrix(rect.Width(), 0, 0, rect.Height(), rect.x1,
rect.y1);
...

Actually the dimensions (and positioning) of text (and other graphics
can be also influenced) by CTM (current transformation matrix)
element.GetGState().SetTransform(), but as long as you keep this
image in the given 'rect' you could do the following:

// assuming C#
element = eb.CreateImage(img, new Matrix2D(rect.Width(), 0, 0,
rect.Height(), rect.x1, rect.y1));
writer.WritePlacedElement(element);

this is equivalent to:

writer.WriteElement(eb.CreateGroupBegin()); // Save the graphics
state
element = eb.CreateImage(img, new Matrix2D());
element.GetGState().SetTransform(rect.Width(), 0, 0, rect.Height(),
rect.x1, rect.y1);
writer.WriteElement(eb.CreateGroupEnd()); // Restore the graphics
state