How do I take into accout page rotation when extracting positioning for page content?

171 views
Skip to first unread message

Support

unread,
Jun 1, 2007, 6:44:09 PM6/1/07
to PDFTron PDFNet SDK
Q:

Would you be able to suggest any form of a fix for a problem we are
having with files where the page orientation is rotated to something
other than the default e_0.

What we are seeing is that if a file has an orientation other than e_0
the boundry box for the text is coming out very small (width)
relative to the amount of text input.

-----

A: The problem is that in these files text is drawn vertically (it is
rotated 90 degrees), but since the page itself is rotated 90 degrees
in the other direction the text appears as if it is not rotated.

In order to take into account effects of page rotation and translation
(page media/crop box may not start at (0,0) origin), you can use
page.GetDefaultMatrix() method to obtain the matrix that transforms
user space coordinates to rotated and cropped coordinates. For
example:

// In C++
Common::Matrix2D pg_mtx = page.GetDefaultMatrix();
...
... obtain coordinates for graphical elements on this page ...
... For example
Rect bbox = element->GetBBox();
// Trasfrom the box to rotated and cropped page...
pg_mtx.Mult(bbox.x1, bbox.y1);
pg_mtx.Mult(bbox.x2, bbox.y2);
... the rotation matrix is now applied to bbox...


// In C#
Common.Matrix2D pg_mtx = page.GetDefaultMatrix();
...
... obtain coordinates for graphical elements on this page ...
... For example
Rect bbox = element.GetBBox();
// Trasfrom the box to rotated and cropped page...
pg_mtx.Mult(ref bbox.x1, ref bbox.y1);
pg_mtx.Mult(ref bbox.x2, ref bbox.y2);
... the rotation matrix is now applied to bbox...

Reply all
Reply to author
Forward
0 new messages