I'm trying to convert a list of files to a single pdf in python. I started by following the answer in this post, but I had the issue that some of the files I want to include in my pdf are already pdfs, while others are jpgs or other image files, and Pillow doesn't directly support reading pdf.
I currently have this
from PIL import Image
from pdf2image import convert_from_path
def pdfsort(filename):
if(filename[-3:].lower()=="pdf"):
return convert_from_path(filename)
else:
return(filename)
images = [
Image.open(pdfsort("dir"+f))
for f in ["file1.jpg","file2.pdf","file3.jpg"]
]
I'm getting the error message "AttributeError: 'list' object has no attribute 'read'". I imagine this is caused by my function. Is there a better way of getting this done?