Q: I convert all the items in the PDF file to a standardized
coordinate system (X horizontal - left to right, Y vertical - top to
bottom). To get the coordinates of the
various items in a path I use (in C#):
Matrix2D matrixPage = page.GetDefaultMatrix(true);
Matrix2D matrixCTM = element.GetCTM();
Matrix2D matrix = matrixPage * matrixCTM;
For rectangle path:
case Element.PathSegmentType.e_rect:
{
double x1 = pathPoints[indexPathPoints++];
double y1 = pathPoints[indexPathPoints++];
double width = pathPoints[indexPathPoints++];
double height = pathPoints[indexPathPoints++];
matrix.Mult(ref x1, ref y1);
matrix.Mult(ref width, ref height);
Rectangle rectangle = new Rectangle(x1, y1, width, height);
}
This normally works, but now I have a PDF file where it's coming in
correctly. Any ideas? The rectangles are off to the right of the page
and
many have negative Y values.
----
A: The problem is related to how you transform the second coordinate
of the rectangle (width/height). The correct code is:
double x1 = pathPoints[indexPathPoints++];
double y1 = pathPoints[indexPathPoints++];
double x2 = x1 + pathPoints[indexPathPoints++];
double y2 = y1 + pathPoints[indexPathPoints++];
matrix.Mult(ref x1, ref y1);
matrix.Mult(ref x2, ref y2);
...