Last active
December 13, 2015 19:28
-
-
Save zeffii/4962354 to your computer and use it in GitHub Desktop.
This file contains 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
# original by andrew.canit | |
# plenty of info in dir(help(canvas.Canvas.drawImage)) | |
import sys | |
import os | |
from reportlab.pdfgen import canvas | |
# from reportlab.lib.pagesizes import letter | |
# from reportlab.lib.units import cm, mm, inch, pica | |
def pdfDirectory(imageDirectory, outputPDFName, width, height): | |
dirim = str(imageDirectory) | |
output = str(outputPDFName) | |
c = canvas.Canvas(output, pagesize=(width, height)) | |
try: | |
for root, dirs, files in os.walk(dirim): | |
for name in sorted(files): | |
lname = name.lower()[-3:] | |
if lname in ["jpg", "gif", "png"]: | |
filepath = os.path.join(root, name) | |
c.drawImage(filepath, 0, 0) #start bottom left, flush to edge | |
c.showPage() | |
c.save() | |
print "PDF of Image directory created" | |
except: | |
print "Failed creating PDF" | |
pdfDirectory(*sys.argv[1:5]) | |
# example usage: python images_to_pdf.py gsm_images gsm.pdf 2400 1600 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment