Pillow: adding multiple images to PDF

Created on 9 May 2017  路  3Comments  路  Source: python-pillow/Pillow

I am trying to add multiple pages in PDF, but for some reason it is not working.

As per the documentation, save_all=True, should work. What am I missing or is this a bug?

import PIL
print(PIL.__version__)

4.1.1

from PIL import Image

a4im = Image.new('RGB',
                 (1654, 2338), 
                 (255, 255, 255))
a4im2 = Image.new('RGB',
                 (1654, 2338), 
                 (255, 255, 255))

img = Image.open("image_1.jpg")
img = img.convert('RGB')
img = img.resize((1600, 720))
a4im.paste(img, (27,10))

img_2 = Image.open("image_2.jpg")
img_2 = img_2.convert('RGB')
img = img.resize((1600, 720))
a4im2.paste(img_2, (27, 10))

a4im.save("out.pdf", save_all=True, append_images=[a4im2])

Most helpful comment

This feature has now been added to Pillow, and will be part of the 4.2 release on July 1.

All 3 comments

While going through the test_file_pdf.py, I realised that, I can first make a GIF image with multiple frames and then, save the document to pdf!

Now my question: Is this is a hack or is this the intended behaviour? :-)

append_images is currently only supported for GIF - http://pillow.readthedocs.io/en/4.1.x/releasenotes/3.4.0.html#append-images-to-gif, http://pillow.readthedocs.io/en/4.1.x/handbook/image-file-formats.html?highlight=image%20file%20formats#saving

I have created a PR to add this feature for PDF, so it may exist in a future version of Pillow.

This feature has now been added to Pillow, and will be part of the 4.2 release on July 1.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

damianmoore picture damianmoore  路  4Comments

indirectlylit picture indirectlylit  路  4Comments

dhsdshdhk picture dhsdshdhk  路  4Comments

mmalenta picture mmalenta  路  3Comments

anonymous530 picture anonymous530  路  3Comments