Skip to content

Instantly share code, notes, and snippets.

@HiCraigChen
Last active September 25, 2019 01:10
Show Gist options
  • Save HiCraigChen/403cbb023cd5e8b3e31bf4e60b3e628f to your computer and use it in GitHub Desktop.
Save HiCraigChen/403cbb023cd5e8b3e31bf4e60b3e628f to your computer and use it in GitHub Desktop.
Convert PDF to image using Python wand library
from wand.image import Image
import os
# Download and read pdf file
os.system("curl https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf -o /tmp/file.pdf")
f = open('/tmp/file.pdf','rb')
infile = f.read()
f.close()
with Image(blob=infile,resolution=150) as img_pdf:
num_pages = len(img_pdf.sequence)
for img in img_pdf.sequence:
img_page = Image(image=img)
img_page.format = 'jpeg'
img_page.save(filename='image.jpg')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment