Generate a PDF file from images

If you want to combine images into a pdf file, then you can do this with a small script in python.

First, run the following commands to setup the project directory

# create a directory for the project
mkdir images_to_pdf

# go into the directory
cd images_to_pdf

# create a virtual environment
python3 -m venv venv # the second venv is the name of the directory where you will create the virtual environment

# activate the virtual environment
source venv/bin/activate

# install pillow
pip install Pillow

# create a directory to store your images to be added into pdf file
mkdir sources

Next, you need to add images into the sources directory.

If the order matter, make sure you name the files with a numerical sequence.

Once you have the project ready, create a python script convert.py with the following content:

#!/usr/bin/env python3

import os

from PIL import Image

images = [
	# it will search for paths like: sources/0.jpg, sources/1.jpg, etc
    Image.open(f'sources/{f}.jpg')
    for f in range(0, 11) # will iterate 10 images
]

pdf_path = 'my-document.pdf'

images[0].save(pdf_path, "PDF", resolution=100.0, save_all=True, append_images=images[1:])

To generate the pdf file, run python3 convert.py and if it runs successfully, it will generate my-document.pdf file.