How to Create a PDF File from a List of Images with Python

How to Create a PDF File from a List of Images with Python

A how-to-guide for generating PDF files from a bunch of images using Python.

I had received the transcripts of my Bachelor's degree around a month ago. I always visualized transcripts as one document consisting of marksheets of all the semesters, but, when I received my transcript, I had four sheets. That was annoying for me, as now I had to do multiple scans to upload my transcript somewhere. To make such an upload easier, I can scan all my sheets one time and create a PDF file from images of those sheets. That will make my life easy with transcript uploads, won't that?

So, for creating a PDF file from a bunch of images, I know of two ways.

  1. I can use web services for such usecase and upload images of my sheets
  2. Use some programming language to do the task

I, a lover of programming and scripting, am inclined to do the latter way. Let's use Python for the task, shall we?

Using Python for this task will help when we have to do such conversion for hundreds of images, as uploading such a number of images manually is cumbersome and will take forever.

For this task, let's use fpdf library of Python.

import os

from fpdf import FPDF

pdf = FPDF()


pdf.set_auto_page_break(0) sets auto page break to False. Setting auto page break to False is important, otherwise, we might have a blank page after each transcript sheet in the PDF.

python programming pdf coding

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Guide to Python Programming Language

Guide to Python Programming Language

Generate QR Code using Python — Python Programming — PyShark

This article will explore how to generate QR code in Python and some useful creation features from pyqrcode library. QR codes recently became more popular than ever before, yet few people know that the first iterations of QR codes were created back in 1990s in Japan for the automotive industry.

Python Programming: A Beginner’s Guide

Python is an interpreted, high-level, powerful general-purpose programming language. You may ask, Python’s a snake right? and Why is this programming language named after it?

Python Hello World Program - Create & Run Your First Python Program in PyCharm

Python Hello World Program - Your first step towards Python world. Learn how to create the Hello World Python program in PyCharm.

Python Programming Tutorials For Beginners

Python Programming Tutorials For Beginners