Skip to content

Instantly share code, notes, and snippets.

@lsloan
Last active May 22, 2024 01:41
Show Gist options
  • Save lsloan/f463cef5cc3015d781cfcc67f42c9ddf to your computer and use it in GitHub Desktop.
Save lsloan/f463cef5cc3015d781cfcc67f42c9ddf to your computer and use it in GitHub Desktop.
A small program to convert the PDF of the PyCon US 2024 venue map to individual PNG images.
import urllib.request
import pymupdf # pip install PyMuPDF
url = ('https://pycon-assets.s3.amazonaws.com/2024/media/'
'documents/DLCC-Floorplan-Marked_up_PyCon_US_2024.pdf')
# url = 'file:DLCC-Floorplan-Marked_up_PyCon_US_2024.pdf'
with urllib.request.urlopen(url) as response:
pdfStream = response.read()
for (n, page) in enumerate(pymupdf.Document(stream=pdfStream).pages(), 1):
imageFilename = f'page-{n}.png'
print(f'Converting page {n} to "{imageFilename}"…')
page.get_pixmap(dpi=300).save(imageFilename)
@lsloan
Copy link
Author

lsloan commented May 22, 2024

I changed the program to use urllib.request instead of requests because the latter cannot handle URLs with the file: schema.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment