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

41 views
Skip to first unread message

Ryan

unread,
May 18, 2017, 6:27:49 PM5/18/17
to PDFTron PDFNet SDK
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);




Reply all
Reply to author
Forward
0 new messages