I have a few 1924 × 2972 JPG files in a folder (/img/). I want to 1) Convert them to PDFs and 2) Combine them into a single PDF. But I am not successful. I am new to python.
In your second loop, you need to actually reference the path to each jpg:
pdf.image(image, 10,210,297)
Edit: additionally, I think you just need the path to each image (rather than opening each image using Image.open
. Try the following:
import glob
from fpdf import FPDF #
imagelist = glob.glob('img/*.jpg')
pdf = FPDF()
# imagelist is the list with all image filenames
for image in imagelist:
pdf.add_page()
pdf.image(image, 10,210,297)
pdf.output("yourfile.pdf", "F")