Created
April 3, 2019 07:29
-
-
Save killthekitten/ca3bbc29cecc3cd9bba20b81afc605c5 to your computer and use it in GitHub Desktop.
Illustration of a bug (a feature?) in pyMuPDF
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, 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