Created
April 30, 2023 13:15
-
-
Save felixbd/be719aec7fa5b46ddd954b503c8bc42b to your computer and use it in GitHub Desktop.
requires: pdfinfo (apt install poppler-utils) and pdf2image (pip3 install pdf2image)
This file contains 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
#!/usr/bin/env python3 | |
import os | |
import glob | |
from pdf2image import convert_from_path | |
# Get a list of all PDF files in the current directory | |
pdf_files = glob.glob('*.pdf') | |
# Loop through each PDF file and convert it to a PNG image | |
for pdf_file in pdf_files: | |
# Convert the PDF file to a list of PIL images | |
pages = convert_from_path(pdf_file) | |
# Loop through each page and save it as a PNG image | |
for i, page in enumerate(pages): | |
page.save(f'{pdf_file[:-4]}-page-{i+1}.png', 'PNG') | |
# Print a message indicating the conversion is complete | |
print(f'Converted {pdf_file} to PNG images.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment