Created
May 24, 2023 15:17
-
-
Save butlerblog/0b979127f157b13098352d64f20c26bd to your computer and use it in GitHub Desktop.
Python script to create a PDF from a directory of sequentially named images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import img2pdf | |
import argparse | |
import os | |
def process_images(min_range, max_range, img_path, prefix, suffix, out_file): | |
images = [] | |
for i in range(min_range,max_range): | |
fname = img_path + prefix + '%0.3d' % i + '.' + suffix | |
print("adding img: " + fname) | |
images.append(fname) | |
out_file.write(img2pdf.convert(images)) | |
img_path = input("Path to image files: ") | |
formatted_img_path = os.path.join(img_path, '') | |
prefix = input("Image file prefix: ") | |
suffix = input("Image file type: ") | |
out_fname = input("Save PDF as (filename.pdf): ") | |
min_range = 1 | |
max_range = input("Number of pages (images): ") | |
max_range = int(max_range) + 1 | |
with open(out_fname, "wb") as out_file: | |
process_images(min_range, max_range, formatted_img_path, prefix, suffix, out_file) | |
print("PDF generation complete!") | |
print("File saved as: " + out_fname) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment