Skip to content

Instantly share code, notes, and snippets.

@killthekitten
Created April 9, 2019 12:10
Show Gist options
  • Save killthekitten/f600f96aedc04be2540f3e23f35d0870 to your computer and use it in GitHub Desktop.
Save killthekitten/f600f96aedc04be2540f3e23f35d0870 to your computer and use it in GitHub Desktop.
Illustrates Pixmap regression introduced in PyMuPDF 1.14.13
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)
@svenw3
Copy link

svenw3 commented May 7, 2019

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