I am trying to convert a PDF into JPEG using Python. Below are the steps I have taken as well as the code but, firstly, here are:
- Expected results: Have 1 JPEG file per page in the PDF file added into my "Output" folder.
- Actual results: The code appears to run indefinitely without any JPEGS being added to the "Output" folder.
Steps taken:
- Installed pdf2image via CMD (pip install pdf2image)
- Installed Poppler.
Note on Poppler: It is required to add it to PATH and I had done this in the environment variables but I kept getting the error pdf2image.exceptions.PDFInfoNotInstalledError: Unable to get page count. Is Poppler installed and in PATH?. So as a workaround, I have added the path in the code directly and I am not receiving this error any longer.
from pdf2image import convert_from_path
path = "D:/Users/<USERNAME>/Desktop/Python/DeratingTool/"
pdfname = path+"<PDFNAME>.pdf"
images = convert_from_path(pdfname, 500,poppler_path=r'C:\Program Files\Release-22.04.0-0\poppler-22.04.0\Library\bin')
output_folder_path = "D:/Users/<USERNAME>/Desktop/Python/DeratingTool/Output"
i = 1
for image in images:
image.save(output_folder_path + str(i) + "jpg", "JPEG")
i = i+1
Any ideas why this doesn't seem to be able to finish would be most welcome.
Thank you.
output_folder? Egimages = convert_from_path(pdfname, 500,poppler_path=r'C:\Program Files\Release-22.04.0-0\poppler-22.04.0\Library\bin', output_folder="D:/Users/<USERNAME>/Desktop/Python/DeratingTool/Output")