You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug: IndexError for Page.get_links after Page.clip_to_rect #4942
When do page.clip_to_rect(...) the page content can be mutilated in a subtle way - such that not all internally caches kept by MuPDF have already been resynchronized.
This happens in your case.
If you execute get_links() before clip_to_rect() things will work, as well as when you force resynchronization with this statement:
Thanks for your warning. Indeed, I was using it here in the reproducer examples but should have used page.bound() or page.rect instead.
The word "roughly" was meant seriously […]
Yeah, instead of using page.clip_to_rect() I implemented it with four almost infinite redaction annotations which let’s me control also how the removal is performed.
Activity
JorjMcKie commentedon Mar 18, 2026
When do
page.clip_to_rect(...)the page content can be mutilated in a subtle way - such that not all internally caches kept by MuPDF have already been resynchronized.This happens in your case.
If you execute
get_links()beforeclip_to_rect()things will work, as well as when you force resynchronization with this statement:mahlzahn commentedon Mar 18, 2026
Thank you! This solves the issue for me, maybe it would be good to document it in https://pymupdf.readthedocs.io/en/latest/page.html#Page.clip_to_rect
mislead me a bit ;)
JorjMcKie commentedon Mar 18, 2026
The true resolution would be to do this resynchronization internally at the right place - e.g. before returning from
clip_to_rect().BTW:
Be extremely careful using
page.cropbox: You seem to assume that this must equal the page rectangle coordinates ... this is wrong!page.rectandpage.cropboxare systematically different if page width and height are different und the page is rotated by 90 or 270.(0, 0).JorjMcKie commentedon Mar 18, 2026
The word "roughly" was meant seriously: redactions ...
page.clip_to_rect()does not remove characters that lap into the rectangle and it leaves images complete untouched.mahlzahn commentedon Mar 18, 2026
Thanks for your warning. Indeed, I was using it here in the reproducer examples but should have used
page.bound()orpage.rectinstead.Yeah, instead of using
page.clip_to_rect()I implemented it with four almost infinite redaction annotations which let’s me control also how the removal is performed.JorjMcKie commentedon Mar 22, 2026
The fix immunizes annotations / links against being invalidated by the method.
julian-smith-artifex-com commentedon Apr 24, 2026
Fixed in pymupdf-1.27.2.3.