Skip to content

Instantly share code, notes, and snippets.

@killthekitten
Created April 3, 2019 07:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save killthekitten/ca3bbc29cecc3cd9bba20b81afc605c5 to your computer and use it in GitHub Desktop.
Save killthekitten/ca3bbc29cecc3cd9bba20b81afc605c5 to your computer and use it in GitHub Desktop.
Illustration of a bug (a feature?) in pyMuPDF
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, stream=png, keep_proportion=True)
return document.write()
if __name__ == "__main__":
result = handle(None)
with open("result.pdf", "wb") as file:
file.write(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment