Understanding coordinates

The coordinate spaces for several components may be defined in several ways.

PDF page coordinates and Android screen coordinates

This tutorial only applies to Xamarin.Android.

When dealing with locations in PDFViewCtrl it is important to understand what coordinate space they are located in. For example when you get (x, y) value from MotionEvent, the location is relative to the screen, not PDF page.

PDF document has its own coordinate system, which differs from Android's view coordinate system. When you ask for the position of an annotation in a PDF document using the Apryse API, the position is given in PDF page coordinates instead of Android screen coordinates. To illustrate this, here is a screen capture of an annotation and a table of its coordinates as 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 (0, 0) is at the bottom left corner of the PDF page. The x axis extends horizontally to the right and y axis extends vertically upward. A page point represents a point in page coordinates.

Apryse Docs Image

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

For example, here is the same page shown as above, but rotated 90 degrees clockwise. Notice how the coordinate (0, 0) is now at the top left corner of the viewport.

Apryse Docs Image

Screen coordinates

In Android views and in the PDFViewCtrl class, the locations of a view are measured in screen coordinates. Point (0, 0) is at the top left corner of the view. The x axis extends horizontally to the right and the y axis extends vertically downward. A screen point represents a point in screen coordinates.

Apryse Docs Image

Since screen coordinates measure Android views, if PDFViewCtrl zooms in, the annotation's screen coordinates may change.

For example, here are two screen captures of the same annotation 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

In PDFViewCtrl, users can flip pages horizontally or vertically. In scrolling coordinates, the point (0, 0) is located at the top left corner of the view in page 1. The x axis extends horizontally to the right and the y axis extends vertically downward.

Apryse Docs Image

Convert between different coordinates

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

Method

Description

ConvPagePtToHorizontalScrollingPt

Converts a point from page space to scrolling space.

ConvPagePtToScreenPt

Converts a point from page space to screen space.

ConvScreenPtToPagePt

Converts a point from screen space to page space.

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales