from PIL import Image
from natsort import natsorted
file_names = os.listdir(file_path)
file_names = natsorted(file_names) #Python doesn't have a built-in way to have natural sorting so I needed to import a specific library to do it
pdfimages = [Image.open(f"{file_path}/{f}") for f in file_names]
pdf_path = file_path + 'pdfname' + '.pdf'
pdfimages[0].save(pdf_path, "PDF" , resolution=100.0, save_all=True, append_images=pdfimages[1:])