Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDF Tm operator

Tags:

pdf

I'm trying to highlight text in a PDF document but I found a Tm operator with the following operands:

0 7.98 -7.98 0 90.8898 715.4183 Tm

The Tm operator is supposed to replace the text matrix and the text line matrix solely on its operands. According to the Pdf Reference, the following operations can be done:

  • Translations [1 0 0 1 tx ty]
  • Scaling [sx 0 0 sy 0 0]
  • Rotation [cos(angle) sin(angle) -sin(angle) cos(angle) 0 0]
  • Skew [1 tan(alpha) tan(beta) 1 0 0]

The format of the operands doesn't match any of the above transformations, which led to the following questions.

  • What is the previously mentioned text matrix supposed to do?
  • How would a several transformations look like? For example Scaling and rotation.
like image 670
Diego A. Rincon Avatar asked Sep 21 '25 01:09

Diego A. Rincon


1 Answers

What is the previously mentioned text matrix supposed to do?

Your matrix

0 7.98 -7.98 0 90.8898 715.4183

(which is the PDF short form for

⌈  0        7.98    0 ⌉
| -7.98     0       0 |
⌊ 90.8898 715.4183  1 ⌋

and unfortunately it is difficult to draw big brackets indeed)

is a combination of a 90° rotation, a scaling by 7.98, and a translation operation by 90.8898, 715.4183. I'll approximate those numbers in the following, 7.98 ≅8, 90.8898 ≅ 91, and 715.4183 ≅ 715:

⌈  0   8  0 ⌉   ⌈  0  8  0 ⌉   ⌈  1   0  0 ⌉
| -8   0  0 | = | -8  0  0 | x |  0   1  0 |
⌊ 91 715  1 ⌋   ⌊  0  0  1 ⌋   ⌊ 91 715  1 ⌋

  ⌈ 8 0 0 ⌉   ⌈  0  1  0 ⌉   ⌈  1   0  0 ⌉
= | 0 8 0 | x | -1  0  0 | x |  0   1  0 |
  ⌊ 0 0 1 ⌋   ⌊  0  0  1 ⌋   ⌊ 91 715  1 ⌋

How would a several transformations look like? For example Scaling and rotation

We have such an example in the decomposition above,

⌈  0  8  0 ⌉   ⌈ 8 0 0 ⌉   ⌈  0  1  0 ⌉
| -8  0  0 | = | 0 8 0 | x | -1  0  0 |
⌊  0  0  1 ⌋   ⌊ 0 0 1 ⌋   ⌊  0  0  1 ⌋

a combination of a scaling by 8 and a rotation by 90°.

like image 188
mkl Avatar answered Sep 23 '25 11:09

mkl