comparison mupdf-source/docs/reference/common/coordinate-system.rst @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
1 Coordinate Systems
2 =================================
3
4 In PDF, the origin (0, 0) of a page is located at its bottom-left corner. In
5 MuPDF, the origin of a page is located at its top-left corner.
6
7 .. image:: /images/img-coordinate-space.webp
8 :width: 75%
9
10 The exact coordinate of the page's corner may not always be (0, 0) but is
11 defined by its CropBox in relation to the MediaBox.
12
13 The rotation of the page also affects the PDF to MuPDF coordinate space
14 relationship; the rotation automatically adjusted for and hidden in the MuPDF
15 space.
16
17 Coordinates are real numbers and measured in points (1/72 of an inch).
18
19 The PDF page may override this convention by setting a UserUnit (must be larger than 1/72").
20
21 Example
22 -------
23
24 In MuPDF interfaces we use the MuPDF coordinate space.
25
26 .. code-block:: javascript
27
28 var rectangle = [0,0,200,200]
29
30 Results in:
31
32 .. image:: /images/200x200-rect.webp
33 :width: 200px
34
35 Working at the PDF object level
36 -------------------------------
37
38 Sometimes you may want to work directly with the PDF objects without using the MuPDF high level functions.
39 When doing this, you need to write the PDF coordinates as the PDF file expects them.
40
41 .. code-block:: javascript
42
43 var contents = document.addStream(`
44 q % Save graphics state
45 200 0 0 200 10 10 cm % Scale and translate to position image
46 /Image1 Do % Fill image
47 Q % Restore graphics state
48 `)
49
50 Then in this case we are working in the PDF coordinate space!
51
52 Use the `PDFPage.prototype.getTransform` to get a matrix that can be used to transform between the coordinate spaces.