Last active
September 25, 2019 01:10
-
-
Save HiCraigChen/403cbb023cd5e8b3e31bf4e60b3e628f to your computer and use it in GitHub Desktop.
Convert PDF to image using Python wand library
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
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