Skip to content

(PDF) inconsistent page.cropbox reference point, when mediabox is shifted #1484

@openandclose

Description

@openandclose

(1)
From The Glossary page,
I expect that when given /MediaBox [ 36 45 607.5 765 ],

>>> page.cropbox
Rect(36.0, 0.0, 607.5, 720.0)

but actually:

Rect(36.0, 45.0, 607.5, 765.0)

If also explicitly given /CropBox [ 36 45 607.5 765 ],
cropbox is as documented.

(2)
So currently there are three rect coordinates used in PyMuPDF.

coord A: as in PDF data

with  y axis inverted,
coord B: top-left aligned, x0 = y0 = 0, as in page.rect
coord C: only top aligned, it seems used only in page.cropbox.

Which coordinates should be used in set_cropbox?

Currently putting coord A returns documented result,
but it is hard to make sense of it.

(3)
Also update the doc for set_mediabox.
(Now RuntimeError: mediabox must start at (0,0),
since (perhaps) b469ab9, 'upload v1.18.7', fitz.i).

To Reproduce (mandatory)

test PDF and test python files are attached.

sample-shifted_medeabox.pdf (only MediaBox defined)
sample-shifted_medeabox2.pdf (MediaBox and CropBox defined)
check_box.py.txt

Your configuration (mandatory)

Linux 5.15.2
Python 3.9.7
PyMuPDF 1.19.3

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions