I'm working on a python script that checks the .pdf files in a directory, creates a new directory for each file, converts the .pdf into images, and writes the images as jpg into the new directory. I'm using pdf2image and have the following code:
import os
#import main
import glob
#import cv2
import matplotlib.pyplot as plt
from pdf2image import convert_from_path
from PIL import Image
path = "C:/Users/d/Desktop/Reis/"
for file in glob.iglob(path + "*.pdf"):
print(file)
name = os.path.basename(file)
filename = name.split(".")[0]
print(filename)
images = os.mkdir(path + filename)
pages = convert_from_path("C:/Users/d/Desktop/Reis/Reis_Wasser_Verhaeltnis.pdf",
350,
poppler_path=r'C:/Program Files/poppler-22.04.0/Library/bin',
output_folder=images)
for i in range(len(pages)):
pages[i].save('page' + str(i) + '.jpg', 'JPEG')
When I run my code I don't get an error message but no images either. Does anyone have an idea what I'm overseeing?
os.mkdir
creates the Folder but it is of type boolean. Thus:
images = os.mkdir(path + filename)
returns only True
and cannot be used as the output folder. My script writes the images into the default project directory.