Skip to content

Instantly share code, notes, and snippets.

@aimerneige
Last active May 14, 2022 09:24
Show Gist options
  • Save aimerneige/3144404aa4dd4630570bd6be14404bc0 to your computer and use it in GitHub Desktop.
Save aimerneige/3144404aa4dd4630570bd6be14404bc0 to your computer and use it in GitHub Desktop.
pdf to images
# coding: utf-8
# pip install pdf2imag
# https://stackoverflow.com/questions/53481088/poppler-in-path-for-pdf2image
import os
from pdf2image import convert_from_path
file_name = 'test'
pdf_file_dir = './'
pdf_file_path = os.path.join(pdf_file_dir, file_name+'.pdf')
images = convert_from_path(pdf_file_path)
output_dir = os.path.join('./', file_name)
if not os.path.isdir(output_dir):
os.makedirs(output_dir)
for i in range(len(images)):
out_file_path = os.path.join(output_dir, f'{file_name}-{i}.jpg')
images[i].save(out_file_path, 'JPEG')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment