Some test text!

Search
Hamburger Icon

Xamarin / Guides / Coordinates

Convert between different coordinates in Xamarin

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

PDFViewCtrl view = new PDFViewCtrl();
PDFDoc doc = new PDFDoc(filename);
view.SetDoc(doc);

int page = 1;
double x = 0, y = 0;

// Converts a point in a page space to a point in screen space.
view.ConvPagePtToScreenPt( ref x, ref y, page);

// Converts a point in screen space to a point in a page space.
view.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

PDF screen capture

Coordinatesx1y1x2y2
PDF page coordinates62.8165.3538.4415.5
Screen coordinates62.01368.61023.9862.5
Scrolling coordinates5063.01368.66024.9862.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.

PDF coordinates

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.

PDF coordinates rotated

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.

screen coordinates

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.

screen coordinates zoom

left (x1)bottom (y1)right (x2)top (y2)
Before zoom in215.81148.8805.8734.6
After zoom in2.41130.0986.8638.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.

scrolling screen coordinates

Trial setup questions? Ask experts on Discord
Need other help? Contact Support
Pricing or product questions? Contact Sales