DynaPDF Manual - Page 487

Previous Page 486   Index   Next Page 488

Function Reference
Page 487 of 839
Such PDF files can be viewed and printed correctly but it is not possible to extract human readable
strings from them.
How to calculate the absolute string position?
The absolute string position can be calculated from the matrices ctm and tm. Before the string
position can be computed the matrix tm must be transformed into user space. This can be done by
multiplying the matrices ctm and tm into another one:
TCTM MulMatrix(TCTM &M1, TCTM &M2)
TCTM retval;
retval.a = M2.a * M1.a + M2.b * M1.c;
retval.b = M2.a * M1.b + M2.b * M1.d;
retval.c = M2.c * M1.a + M2.d * M1.c;
retval.d = M2.c * M1.b + M2.d * M1.d;
retval.x = M2.x * M1.a + M2.y * M1.c + M1.x;
retval.y = M2.x * M1.b + M2.y * M1.d + M1.y;
return retval;
The usage is as follows:
TCTM m = MulMatrix(stack.ctm, stack.tm);
Note that the order in which the matrices are multiplied is important; the reversed order would
produce an incorrect result.
Now we need a function that transforms a point with the matrix:
void Transform(TCTM &M, double &x, double &y)
double ox = x;
x = ox * M.a + y * M.c + M.x;
y = ox * M.b + y * M.d + M.y;
The text position can now easily calculated as follows:
// Get the text matrix in user space
TCTM m = MulMatrix(stack.ctm, stack.tm);
double x = 0.0;
double y = 0.0;
Transform(m, x, y);
How to caluculate the font size?
The font size that is provided in the structure TPDFStack is measured in text space. If you want to
know the visible font size then the value must be transformed to user space:

Previous topic: Possible encoding issues

Next topic: How to calculate the rotation angle?, How to find and replace text in a page?