import osimport img2pdfwith open("output.pdf", "wb") as f: f.write(img2pdf.convert([i for i in os.listdir('.') if i.endswith(".jpg")]))