Skip to content

Instantly share code, notes, and snippets.

@sagorbrur
Created October 20, 2019 09:20
Show Gist options
  • Save sagorbrur/f7bdf3fea732b14977745057467eca99 to your computer and use it in GitHub Desktop.
Save sagorbrur/f7bdf3fea732b14977745057467eca99 to your computer and use it in GitHub Desktop.
# Dependecies
# python 3
# pip install fpdf
# to run: python fpdf.py
from fpdf import FPDF
from PIL import Image
import os
listPages = os.listdir("images")
def makePdf(pdfFileName, listPages, dir = ''):
if (dir):
dir += "/"
cover = Image.open(dir + str(listPages[0]))
width, height = cover.size
pdf = FPDF(unit = "pt", format = [width, height])
for page in listPages:
pdf.add_page()
pdf.image(dir + str(page), 0, 0)
pdf.output(pdfFileName + ".pdf", "F")
makePdf('output.pdf', listPages, 'images')
# ref: https://stackoverflow.com/questions/27327513/create-pdf-from-a-list-of-images
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment