How to translate Adobe cursor points to actual PDF page points?

Question:

Adobe Acrobat can display the coordinates of the mouse in Pt points. However, these values don’t seem to work with the PDFNet SDK.

How can use those coordinates?

Answer:

Those values are always from the top left corner of the visible page, but as you experienced, they don’t actually match to the actual coordinates of the PDF page. At the very least the y-axis needs to be flipped.

The following code takes two points from adobe acrobat, and translates them to the correct page coordinates of that particular page. It also adds a Rectangle annotation for demonstration purposes.

`
Page page = doc.GetPage(1);
Matrix2D mtx = page.GetDefaultMatrix(true);
double x1 = 54;
double y1 = 68;
double x2 = 160;
double y2 = 130;
mtx.Mult(ref x1, ref y1);
mtx.Mult(ref x2, ref y2);
pdftron.PDF.Annots.Square sqr = pdftron.PDF.Annots.Square.Create(doc, new Rect(x1, y1, x2, y2));
page.AnnotPushBack(sqr);

`