-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplitpdf
More file actions
executable file
·36 lines (23 loc) · 744 Bytes
/
splitpdf
File metadata and controls
executable file
·36 lines (23 loc) · 744 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python
"""
Splits the given PDF into parts at the given page numbers
Depends:
* pdftk
"""
import sys
import subprocess
if len(sys.argv) < 3:
print 'Usage:\n\t<pdf file> <page number to split at> [...]'
sys.exit(1)
split_points = []
file_name = sys.argv[1]
for split_point in sys.argv[2:]:
split_points.append(split_point)
# rotate
start_page = 1
for page in split_points:
end_page = str(int(page) - 1)
subprocess.call(['/usr/bin/pdftk', '%s' % file_name, 'cat', '%s-%s' % (str(start_page), str(end_page)), 'output', '%s.pdf' % str(start_page)])
start_page = page
end_page = 'end'
subprocess.call(['/usr/bin/pdftk', '%s' % file_name, 'cat', '%s-%s' % (start_page, end_page), 'output', '%s.pdf' % start_page])