Skip to content

Incorrect PixMap from page due to cached data from other PDF #4388

@stijnvermeeren-swisstopo

Description

Description of the bug

Cached data from a one PDF file can cause incorrect colors and shapes when generating a PixMap of a page of a different PDF file.

The issue does not appear when only one PDF file is opened, and explicitly clearing the cache with pymupdf.TOOLS.store_shrink(100) also avoids the problem.

How to reproduce the bug

BOZ1.pdf
BUL1.pdf

Just opening one file and generating a PixMap works correctly:

import pymupdf

bul = pymupdf.open("BUL1.pdf")
bul.load_page(0).get_pixmap().save("correct1.png")
bul.close()

Creating a PixMap of the other PDF first, breaks the PixMap of the second PDF (wrong colors and shapes)

import pymupdf

boz = pymupdf.open("BOZ1.pdf")
boz.load_page(0).get_pixmap()
boz.close()

bul = pymupdf.open("BUL1.pdf")
bul.load_page(0).get_pixmap().save("wrong.png")
bul.close()

Clearing the cache in between serves as a workaround:

import pymupdf

boz = pymupdf.open("BOZ1.pdf")
boz.load_page(0).get_pixmap()
boz.close()

pymupdf.TOOLS.store_shrink(100)
bul = pymupdf.open("BUL1.pdf")
bul.load_page(0).get_pixmap().save("correct2.png")
bul.close()

Fragment of the incorrect PixMap:

Image

Corresponding fragment of the original PDF / correct PixMap:

Image

PyMuPDF version

1.25.4

Operating system

Linux

Python version

3.11

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions