Created
September 26, 2017 16:38
-
-
Save ckunte/903c1dea176497861433a2a0afd08572 to your computer and use it in GitHub Desktop.
When run from a parent folder, this script combines all pdf files contained within subfolders, e.g., this is useful in combining platform-wise layout drawings.
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
#!/usr/bin/env python | |
# -*- coding: UTF-8 -*- | |
''' | |
2014 ckunte | |
''' | |
import os | |
import platform | |
platforms = os.walk('.').next()[1] | |
for platform in platforms: | |
msg = 'echo "Processing ' + str(platform) + ' ..";' | |
cdr = 'cd ' + str(platform) + ';' | |
if platform.system() == 'Darwin': | |
cmd = '/System/Library/Automator/Combine\ PDF\ Pages.action/Contents/Resources/join.py -o' + str(platform) + '-layout.pdf *.pdf;' | |
else: | |
cmd = 'gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=' + str(platform) + '-layout.pdf *.pdf;' | |
os.system(msg + cdr + cmd) | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Clean up file and folder names: Be aware that the
os.walk()
will not pick-up folders with long file names. Folders (and preferably files) with long names will need to be renamed first into short names, which can be done usingzmv
as follows: