I am using the following code to save pdf pages as images but its not storing as >JPEG but it is storing as >PPM file. How do I solve it?
from pdf2image import convert_from_path
pages = convert_from_path(path_to_pdf, output_folder=path_to_output, poppler_path=poppler_path)
for i in range(len(pages)):
print(type(pages[i]))
pages[i].save('page' + str(i) + '.jpg', 'JPEG')
Here is what is happening... With this line:
You are actually doing 2 things:
.ppmfiles to the output folders, andpages, which arePIL.PpmImagePlugin.PpmImageFileobjects.The actual saving of the object to a JPEG is made after, with
This means that to obtain the result you want to obtain, you just have to avoid providing the
output_folderin theconvert_from_pathfunction and provide it while saving instead, as such: