Skip to content

Instantly share code, notes, and snippets.

@LordAmit
Last active December 21, 2015 14:39
Show Gist options
  • Save LordAmit/6321454 to your computer and use it in GitHub Desktop.
Save LordAmit/6321454 to your computer and use it in GitHub Desktop.
script to convert sets of jpgs into a single, compact pdf. Works well enough for me. might need some tweaking.
import subprocess
cmd_list_jpg = 'ls -C -1 | grep .jpg'
all_files = subprocess.check_output(cmd_list_jpg, shell = True)
for i in all_files.split('\n'):
if i.find('convert') != -1:
continue
subprocess.check_output('convert {0} {0}.pdf'.format(i), shell = True)
cmd_output = 'ls -1 -v | grep jpg.pdf'
files = subprocess.check_output(cmd_output, shell = True).split('\n')
all_files_in_space = ''
for i in files:
all_files_in_space += i
all_files_in_space += ' '
cmd_convert_cat_pdf = 'pdftk {0} cat output output.pdf'.format(all_files_in_space)
subprocess.check_output(cmd_convert_cat_pdf, shell = True)
for i in files:
if len(i) > 3:
cmd_rm = 'rm {0}'.format(i)
subprocess.check_output(cmd_rm, shell = True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment