Skip to content

Instantly share code, notes, and snippets.

@saltlakeryan
Last active September 30, 2015 17:22
Show Gist options
  • Save saltlakeryan/382865ac9844b4014af1 to your computer and use it in GitHub Desktop.
Save saltlakeryan/382865ac9844b4014af1 to your computer and use it in GitHub Desktop.
finds tifs and puts them into pdf file
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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment