Convert between different coordinates in Xamarin

PDFViewCtrl allows you to convert from one coordinate system to another with ease.

C#

1PDFViewCtrl view = new PDFViewCtrl();
2PDFDoc doc = new PDFDoc(filename);
3view.SetDoc(doc);
4
5int page = 1;
6double x = 0, y = 0;
7
8// Converts a point in a page space to a point in screen space.
9view.ConvPagePtToScreenPt( ref x, ref y, page);
10
11// Converts a point in screen space to a point in a page space.
12view.ConvScreenPtToPagePt( ref x, ref y, page);

Understanding coordinates

PDF documents have their own coordinate system, which is different from the screen coordinate system of the viewer. For instance, when asking for the position of an annotation element in a PDF document using the Apryse API, the position is given in PDF page coordinates instead of screen coordinates.

Here is an example of a screen capture and table of PDF page coordinates, screen coordinates, and scrolling coordinates

Apryse Docs Image

Coordinates

x1

y1

x2

y2

PDF page coordinates

62.8

165.3

538.4

415.5

Screen coordinates

62.0

1368.6

1023.9

862.5

Scrolling coordinates

5063.0

1368.6

6024.9

862.5

PDF page coordinates

In a PDF document, the location origin (0, 0) is at the bottom left corner of the PDF page. The x axis is positive horizontally to the right and y axis is positive vertically upward. A page location point represents a point in page coordinates. Page points by default is 1⁄72 inch. So an 8.5 x 11 inch page would be 612 x 792 points.

Apryse Docs Image

A PDF page can have a rotation associated with it. In this case, the location origin (0, 0) may no longer correspond to the bottom left corner of the page.

For example, here is the page above rotated 90 degrees clockwise. Notice how the location origin (0, 0) is now at the top left corner of the viewport.

Apryse Docs Image

Screen coordinates

In the PDFViewCtrl class, the location points of the viewer are measured in screen coordinates. Location origin (0, 0) is at the top left corner of the viewport. The x axis is positive horizontally to the right and the y axis is positive vertically downward. A screen location point represents a point in screen coordinates.

Apryse Docs Image

Since screen coordinates align to the viewer, if PDFViewCtrl zooms in, then an element's screen coordinates may change.

For example, here are two screen captures of the same annotation element before and after zooming in, and a table showing how its screen coordinates change.

Apryse Docs Image

left (x1)

bottom (y1)

right (x2)

top (y2)

Before zoom in

215.8

1148.8

805.8

734.6

After zoom in

2.4

1130.0

986.8

638.8

Scrolling coordinates

With PDFViewCtrl, users can flip pages horizontally or vertically. For scrolling coordinates, the location origin (0, 0) is located at the top left corner of the viewer in page 1. The x axis is positive horizontally to the right and the y axis is positive vertically downward.

Apryse Docs Image

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales