Created
April 9, 2019 12:10
Illustrates Pixmap regression introduced in PyMuPDF 1.14.13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fitz | |
import io | |
import requests | |
PDF_URL = "https://github.com/pymupdf/PyMuPDF/raw/master/examples/colordbHSV.pdf" | |
PNG_URL = "https://www.onlygfx.com/wp-content/uploads/2018/07/12-grunge-brush-stroke-banner-11.png" | |
def handle(_): | |
pdf = requests.get(PDF_URL).content | |
png = requests.get(PNG_URL).content | |
rect = fitz.Rect(0, 0, 400, 50) | |
document = fitz.open(stream=pdf, filetype="pdf") | |
for page in document: | |
page.insertImage(rect, pixmap=fitz.Pixmap(png), keep_proportion=True) | |
return document.write() | |
if __name__ == "__main__": | |
result = handle(None) | |
with open("result.pdf", "wb") as file: | |
file.write(result) |
Segfaults on macOS Mojave (10.14.3), too. Stream and filename work.
Reverting to pip install pymupdf==1.14.12
works fine with pixmap, so there is an error introduced in 1.14.13?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your example works always, if you take
stream
instead of pixmap.(Not to mention, that the pixmap should be created only once, outside the loop for every page ...)
So there is a problem with specifically pixmap now ...