-1

I have folders that contains many jpg files.I want them to convert into PDF files.

Every folder should made into a separate PDF.

Please help I am new to python.

And if possible can I do it in one shot.

1 Answers1

0

Possible duplicate

The best method to convert multiple images to PDF so far is to use PIL purely

Erkin
  • 96
  • 1
  • 5
  • `import os import img2pdf with open("output.pdf", "wb") as f: f.write(img2pdf.convert([i for i in os.listdir('path/to/imageDir') if i.endswith(".jpg")]))` – Erkin Apr 09 '21 at 05:40
  • [ref](https://stackoverflow.com/a/45990883/14864237) – Erkin Apr 09 '21 at 05:41
  • Thanks. can I get separate PDFs from it – Sandesh Apr 09 '21 at 08:15
  • `import os import img2pdf dirname = r'C:\Users\Erkin\Desktop\img' imgs = [] for fname in os.listdir(dirname): if not fname.endswith(".jpg"): continue path = os.path.join(dirname, fname) if os.path.isdir(path): continue imgs.append(path) x = 0 for img in imgs: with open(r'C:\Users\Erkin\Desktop\img\name'+str(x)+'.pdf',"wb") as f: f.write(img2pdf.convert(img)) x += 1` – Erkin Apr 09 '21 at 08:33
  • here you are tweak and use – Erkin Apr 09 '21 at 08:33
  • Thank you very much ❤️ I will try it – Sandesh Apr 10 '21 at 06:19