python 3

CONVERT one or more TIF Files into a PDF:

1. Keep all TIF Files in one Folder
2. save following script as “c.py” file
3. from command promt, go to the folder
4. python c.py .

import img2pdf, sys, os, time

if len(sys.argv) > 1:
image_directory = sys.argv[1]
print (“I’m looking for TIFs in “, image_directory)
else:
print (“Please tell me the directory to look in”)
sys.exit()

image_files = []

for root, dirs, files in os.walk(image_directory):
for file in files:
if file.endswith(“.tif”) or file.endswith(“.TIF”):
print (“Discovered this TIF: “, os.path.join(root, file))
image_files.append(os.path.join(root, file))

if image_files:
output_file = time.strftime(“%Y%m%d-%H%M%S”) + “.pdf”
print (“Putting all TIFs into “, output_file)
pdf_bytes = img2pdf.convert(image_files)
file = open(output_file,”wb”)
file.write(pdf_bytes)
else:
print (“Couldn’t find any TIFs”)