-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpdfsplit.py
More file actions
executable file
·32 lines (23 loc) · 819 Bytes
/
Copy pathpdfsplit.py
File metadata and controls
executable file
·32 lines (23 loc) · 819 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
#!/usr/bin/python
# -*- encoding: utf-8 -*-
from subprocess import call
import sys
import os
from CoreGraphics import *
def splitPDF(fname):
inputDoc = CGPDFDocumentCreateWithProvider(CGDataProviderCreateWithFilename(fname))
maxPages = inputDoc.getNumberOfPages()
baseFN = os.path.splitext(os.path.basename(fname))[0]
pageRect = CGRectMake (0, 0, 612, 792)
for pageNum in range(1, maxPages+1):
outputFN = '%s-%d.pdf' % (baseFN, pageNum)
writeContext = CGPDFContextCreateWithFilename(outputFN, pageRect)
mediaBox = inputDoc.getMediaBox(pageNum)
writeContext.beginPage(mediaBox)
writeContext.drawPDFDocument(mediaBox, inputDoc, pageNum)
writeContext.endPage()
if len(sys.argv) < 2:
print("")
sys.exit(1)
else:
splitPDF(sys.argv[1])