Skip to content

Instantly share code, notes, and snippets.

@OriLiMu
Created August 13, 2024 19:10
Show Gist options
  • Save OriLiMu/f445e799e52a6e2a651f838f2248c867 to your computer and use it in GitHub Desktop.
Save OriLiMu/f445e799e52a6e2a651f838f2248c867 to your computer and use it in GitHub Desktop.
python pdf 2 image
  • install pdf2image
  • install poppler choco install poppler

Convert PDF to Image using Python - GeeksforGeeks

# -*- coding: utf-8 -*-
from pdf2image import convert_from_path
import glob
import os

path = "*.pdf"
folder_name = "images"

# check if folder exists
if not os.path.exists(folder_name):
    # create the folder
    os.makedirs(folder_name)

for fname in glob.glob(path):
    print(fname)
    images = convert_from_path(fname)
    for i in range(len(images)):
        images[i].save('images/' + fname + 'page' + str(i) + '.jpg', 'JPEG')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment