---
title: Coordinates
description: "EmbedPDF has one way to say where something is: points from the page's top-left corner, y going down. Pixels only come in when you draw."
---
{/* Generated from docs/content — edit there, then `pnpm docs:sync`. */}
# Coordinates
Every position in EmbedPDF is in **page coordinates**: points (1/72 inch) from the top-left corner of
the page as it's shown, with y going down, like HTML. Annotations, text, search results, selections,
form fields and the places you scroll to all use them. A box is `{ x, y, width, height }` and a point
is `{ x, y }`:
```ts
annotation.rect;
// { x: 100, y: 80, width: 20, height: 20 }
```
Colors work the same everywhere too: hex strings such as `'#dc143c'`. Angles are degrees, clockwise.
## Pass values straight through
Because every part speaks the same coordinates, a value from one goes to another as it is. A comment
thread knows where its first comment is, and that's where the Stage should go:
There's nothing to convert, whether the page is zoomed, rotated or scrolled. A search match says
where it is the same way, and the Stage goes there:
## Pages
A call that takes a page takes its `ref` or its index. A `ref` stays the same when pages move, so keep
refs, not indexes, in your own state. Everything that is on a page hands you its page's ref, such as
`annotation.ref.page` or a search hit's `hit.page`. A ref is an object, so compare two with
`pageRefsEqual(left, right)` from `/runtime`, not `===`.
```ts
stage.goToPage(4); // the fifth page, counting from 0
stage.goToPage(hit.page); // the page of a search hit
```
## Pixels, only when you draw
Pixels change with every zoom, rotation and scroll, so nothing in EmbedPDF stores them. When you draw
something of your own on a page, convert at the last moment with the page's `transform`. Which call
depends on where you draw:
- **On the page**, in the Stage's or inside ``, with the
layers: that box turns with the page, so convert for zoom only, with `toPixels`. What you draw turns
along.
- **Over the page**, in its [page chrome](../viewing/stage#labels-and-buttons-on-every-page): that
box stays upright, so convert with `pageToView`, which includes the page's turn.
An [annotation renderer](../annotations/custom-rendering) converts nothing: it draws into a frame the
layer places and turns for it.
| From | To | On the page | Over the page |
| :---------------- | :---------------- | :---------------------------------- | :------------------------------------ |
| A point on a page | Pixels | `page.transform.toPixels(point)` | `page.transform.pageToView(point)` |
| A box on a page | Pixels | two corners through `toPixels` | `page.transform.pageToViewRect(box)` |
| Pixels | A point on a page | `page.transform.fromPixels(point)` | `page.transform.viewToPage(point)` |
| A pointer event | A point on a page | `page.toPagePoint(event.clientX, event.clientY)` | the same |
To place many things over a page at once, put them in a container with `transform:
page.transform.cssMatrix` and `transform-origin: 0 0`, and give them page coordinates: the browser
does the zoom and the turn.
> **Try it:** click a page to drop a pin, then zoom and turn the view. Each pin keeps its numbers
> and its spot on the page; only its pixels change.
## Tools that use the PDF file's numbers
The PDF file stores positions in its own numbers, with y going up, and a page can sit anywhere in
them. You only meet those numbers next to a tool that reads them, such as iText, PDFBox or Acrobat
JavaScript. `page.pdfCropBox` says where the page sits in them, and `pdfRectOf()`, `pdfPointOf()`,
`pageBoxOf()` and `pagePointOf()` convert. See [Coordinates](/docs/engine/concepts/coordinates) in the
engine docs.
## Cheat sheet
| You're… | Use | Shape |
| :---------------------------------------------------- | :------------------ | :--------------------------------------- |
| Working with annotations, text, search or `reveal` | page coordinates | `{ x, y, width, height }` and `{ x, y }` |
| Drawing on a page right now | `page.transform` | pixels: convert, never store (`toPixels` on it, `pageToView` over it) |
| Talking to a tool that reads the PDF's own numbers | `pdfRectOf()` | `{ left, bottom, right, top }` |
**Bringing your own coordinate system?** Page coordinates are a plain frame in points with y going
down, so one transform maps them into yours.