Created
September 14, 2016 20:34
-
-
Save hig3/e61aab915d0d3a293850d6236a0e399c to your computer and use it in GitHub Desktop.
一定ページ数の複数文書が連結されたPDFファイルをpdftkで分割して, 標準入力からリストとして与えられたファイル名をつける Python スクリプト
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
# distpdf.py inname outname period start end docopy | |
# 0 =< start, end < periodb | |
# Example: distpdf.py in out 3 1 2 0 | |
import sys | |
import os | |
import shutil | |
import re | |
markdir="./" | |
inname=sys.argv[1] | |
outname=sys.argv[2] | |
period=int(sys.argv[3]) | |
start=int(sys.argv[4]) | |
end=int(sys.argv[5]) | |
docopy=int(sys.argv[6]) | |
i=0 | |
for line in sys.stdin: | |
if re.match("^#",line): | |
continue | |
if re.match("^$",line): | |
continue | |
tmp="pdftk " + inname + ".pdf" | |
tmp+=" cat %d-%d " %(i*period+1+start,i*period+1+end) | |
tmp+=" output " + markdir + outname + line[0:7] + ".pdf" | |
print (i+1),tmp | |
if docopy: | |
os.system(tmp) | |
i=i+1 | |
tmp="pdftk " + inname + ".pdf" | |
tmp+=" cat %d-%d " %(i*period+1+start,i*period+1+end) | |
tmp+=" output " + outname + "_rest.pdf" | |
print (i+1),tmp | |
if docopy: | |
os.system(tmp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment