Last active
December 21, 2015 14:39
-
-
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.
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
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