Click here to Skip to main content
15,891,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this code that combines several images into one PDF file, and it was very good for some time, and then when merging images into a PDF file, it added an additional image to the images, which is the first image so that if I had four images, I found that he added a fifth image, which is a repetition of the image. The first and I don't know what the problem is, I tried several ways and I didn't succeed in that. I hope to get help with that.

Python
import PIL
import os
import os.path
from PIL import Image

f = r'path'

li1 = []
count = 0
for file in os.listdir(f):
    f_img = f+"/"+file
    img = Image.open(f_img).convert('RGB')
    li1.append(img)
img.save(f+file+'.pdf', save_all=True, append_images=li1)


What I have tried:

I tried several modifications and it didn't help.
Posted
Updated 6-May-22 11:13am
v2
Comments
Richard MacCutchan 5-May-22 5:29am    
You are calling img.save on the object last created by Image.open. Should that not be Image.save?
Rajeev Jayaram 5-May-22 6:51am    
Which version of PIL are you using?

1 solution

Can you try using range,
li1 = [Image.open(f_img_"{imageNumber}.jpg").convert('RGB') for imageNumber in range(2, 100)]


Hope this solves your issue.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900