Reputation: 27
I have the following PDF document:
Which is generated printing an image with the default image viewer of Windows. And I try to draw a rectangle across the page border with this code:
from fitz import Document
doc = fitz.Document('pixelated-image.pdf', filetype="pdf")
page.draw_rect(page.rect, color=(0, 0, 1), width=2)
doc.save('pixelated-image-with-bounded-page.pdf')
doc.close()
But I get this file:
https://github.com/pymupdf/PyMuPDF/files/14822508/pixelated-image-with-bounded-page.pdf
Does someone know why the page.rect doesn't match with the real page size? I need to transform those dimensions somehow? Doing some tests, I've discovered that the real page dimension is more or less:
Rect(0, -279.95, 793.2, 841.4)
However, page.rect gives me the following dimension:
Rect(0.0, 0.0, 595.2757568359375, 841.8900146484375)
Thanks.
Upvotes: 0
Views: 166
Reputation: 27
Finally, I've resolved the problem converting the PDF to PDF before to draw the positions:
doc = fitz.open(filename, fitz.Document(join('examples', 'doc.pdf'), filetype="pdf")).convert_to_pdf())
page = doc[0]
images = page.get_images(full=True)
image = images[0]
page.draw_rect(page.rect, color=(0, 0, 1), width=2)
The reason, I don't know, but it works.
Upvotes: 0