Rework how pdf files are created

This commit is contained in:
Stephan Porada 2020-06-02 16:43:12 +02:00
parent 004890b35e
commit 194156d862

View File

@ -28,14 +28,22 @@ def parse_arguments():
def merge_images(input_dir, output_dir, output_file_base, zip): def merge_images(input_dir, output_dir, output_file_base, zip):
try: try:
os.mkdir(output_dir) os.mkdir(output_dir)
tmp_dir_path = os.path.join(input_dir, 'tmp')
os.mkdir(tmp_dir_path)
except FileExistsError: except FileExistsError:
pass pass
cmd = 'ls -Q -v "{i}"/*.* > "{i}"/file_list.txt'.format(i=input_dir) cmd = 'ls -Q -v "{i}"/*.* > "{i}"/file_list.txt'.format(i=input_dir)
subprocess.run(cmd, shell=True) subprocess.run(cmd, shell=True)
cmd = 'convert @"{}"/file_list.txt -compress LZW "{}"/"{}".pdf'.format(input_dir, output_dir, output_file_base) # noqa cmd = ('mogrify -compress LZW -format pdf ',
+ '-path @"{o}" "{i}"/file_list.txt').format(i=input_dir,
o=tmp_dir_path)
subprocess.run(cmd, shell=True) subprocess.run(cmd, shell=True)
cmd = 'rm "{}"/file_list.txt'.format(input_dir) cmd = 'rm "{i}"/file_list.txt'.format(i=input_dir)
subprocess.run(cmd, shell=True) subprocess.run(cmd, shell=True)
cmd = ('pdftk "{tmp_dir_path}"/*.pdf cat ',
+ 'output "{o}"/"{ofb}".pdf').format(i=tmp_dir_path,
o=output_dir,
ofb=output_file_base)
if zip is not None: if zip is not None:
# Remove .zip file extension if provided # Remove .zip file extension if provided
if zip.endswith('.zip'): if zip.endswith('.zip'):