Search code examples
pythonpdfreportlab

Python Multiple .PNG Files per PDF Page


I am relatively new to the Python-PDF relationship. If I had a list of .PNG files/pictures, how would I go about creating a PDF document with these files/pictures? And is it possible to have, for example, 4 per page? I would not need any other formatting... the requirement is very basic.

Thanks


Solution

  • There may be a python-reportlab solution, but based on your requirement, you probably don't need it. You can simply use ImageMagick to accomplish the same.

    First merge multiple PNGs into one PNG destined to be one page

    montage -mode concatenate a*.png group_a.png
    montage -mode concatenate b1.png b2.png b3.png b4.png group_b.png
    ...
    

    Then simply

    convert group_*.png one.pdf
    

    The resulting PDF would have 2 pages, each of which contains multiple PNGs.