0

I wrote a python application that converts images to PDF's using PIL. The method below takes all images in a given directory, converts them to RGB, then is supposed to save all the images as one *.pdf file. However, I'm unable to figure out how to provide the extension .pdf to the file output.

Concatenating does not work, I get error:

"Unknown file extension: {}.format(ext))

def multi_convert(file_path: str):
    for path in Path(file_path).iterdir():
        path = Image.open(path)
        path.convert('RGB')
    extension = 'file.pdf'
    final_file = file_path + extension
    path.save(final_file, save_all=True, append_images=path)
lezaf
  • 432
  • 2
  • 9
  • Changing an image file's extension will not convert it into PDF format. You will need to use some third-party module (or launch some external program) to do that. BTW, a file's extension is just the part from the last `.` character until the end. i.e. `pdf`. – martineau Nov 29 '20 at 01:29
  • 1
    Welcome to Stack Overflow! Does this help? [Create PDF from a list of images](https://stackoverflow.com/questions/27327513/create-pdf-from-a-list-of-images) – Ann Zen Nov 29 '20 at 01:32
  • 1
    @AnnZen Thank you! That is very helpful. I've modified it to fit my needs, now just trying to get it working again. :) Much appreciated. – BuddhaRandom Nov 29 '20 at 21:47

0 Answers0