Skip to content

Is it possible to change the rect of a page after its creation? #845

Answered by JorjMcKie
jloehel asked this question in Q&A
Discussion options

You must be logged in to vote

How can I change the rect of a page?

Sure you can do that ... at the risk of displacing stuff already on the page. But if the page is empty, simply do page.setMediaBox(rect) :

>>> import fitz
>>> doc=fitz.open()
>>> page=doc.new_page()
>>> page.rect
Rect(0.0, 0.0, 595.0, 842.0)
>>> page.setMediaBox(fitz.Rect(fitz.PaperRect("a3")))
>>> page.rect
Rect(0.0, 0.0, 842.0, 1191.0)
>>> 

In addition, once you have inserted a few things of which you know which rectangle rect contains them all, you can "shrink" the visible page rectangle to that rect:

rect = fitz.Rect(100, 100, 400, 500)  # assuming this contains the stuff that should be visible
page.setCropBoc(rect)
>>> page.rect
Rect(0.0, 0.0, 3…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@JorjMcKie
Comment options

Answer selected by jloehel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants