Skip to content
Advertisement

I am fetching images and want save images in single pdf file

I am fetching images and want to save images into single pdf file.

Below is the code which is creating multiple pdf for multiple images but I want all images should saved into single pdf :

in = Image.open(r". Outputdemod.png" % i)
im = im.convert('RGB')
im = im.crop((left, top, right, bottom))
print(im)
imagelist = [im] print(imagelist)
pdf_path = im.save(r". pdfmy_images%d.pdf" % i, save_all=True, append_images=imagelist)
in.close()
print("successfully made pdf file")

Could you please help me to resolve this?

Advertisement

Answer

Try this:

pdf = FPDF()

for img in [Image.open(r".Outputdemod.png" * i)]:
    im = img.convert('RGB')

    cropped img = im.crop((left, top, right, bottom)) 
    cropped_img.save(r".Outputcropped%d.png" % i) 
    pdf.add page ()
    pdf.image (r".Outputcropped%d.png" & i, randint(1,20),randint(1, 20))

pdf.output('finalpdf.pdf', 'f')
Advertisement