(An easy way to) convert images to pdf from python

Post date: Jan 8, 2016 6:45:37 PM

I decided to use imagemagick in terminal to convert the images into pdf. So, first we need to install imagemagick.

If you are using Mac, we can install via brew:

> brew update
> brew upgrade
> brew install imagemagick

Now, you can use the command below to convert images into a pdf file.

> convert img1.jpg img2.png img3.jpg pdf_out.pdf

So, in my python code, I will call the convert command in terminal from python.

>>> import os
>>> os.system("convert "+' '.join(['img1.jpg', 'img2.png', 'img3.jpg'])+' pdf_out.pdf')

Done!

useful resources:

- Nice summary of using terminal command line via python.