I have a image file list and I would like to generate a single output.pdf file with these images.
The following code works with one image file only (here the first element of image_list):
with open("output.pdf","wb") as f, io.BytesIO() as output:
img = Image.open(image_list[0])
img.save(output, format='tiff')
f.write(img2pdf.convert(output.getvalue()))
How can I adapt this code to work with the complete list of image files ?
I tried :
with open("output.pdf","wb") as f, io.BytesIO() as output:
img = Image.open(image_list[0])
img.save(output, format='tiff')
img2 = Image.open(image_list[1])
img2.save(output, format='tiff')
f.write(img2pdf.convert(output.getvalue()))
but it doesn't work (the created pdf contain only the last image, ie image_list[1])
A possible hack could be to run it through ImageMagick's convert:
import os
os.system('convert '+' '.join(image_list)+' output.pdf')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With