# How do I calculate transformation matrix that maps text elements to PDF user space?

Q:

How do I calculate transformation matrix that maps text elements to
PDF user space?
-----

A:
The rotation for the entire page is specified using /Rotate attribute
in page dictionary. Using PDFNet you can use page.GetRotation() method
to obtain this value.

Alternatively you can use page.GetDefaultMatrix() to obtain the
transformation matrix that maps PDF page user space coordinates to
rotated and cropped coordinates. To find the actual trasformation
matrix used to place text on the page you need to multiply
GetDefaultMatrix() with element's CTM and GetTextMatrix():

Matrix2D text_mtx = page.GetDefaultMatrix() * element->GetCTM() *
element->GetTextMatrix();