-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcombinePdf.py
More file actions
29 lines (23 loc) · 822 Bytes
/
combinePdf.py
File metadata and controls
29 lines (23 loc) · 822 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
import os
from pyPdf import PdfFileWriter, PdfFileReader
# Creating an object where pdf pages are appended to
output = PdfFileWriter()
# Creating a routine that appends files to the output file
def append_pdf(ipFile, output=output):
[output.addPage(ipFile.getPage(page_num)) for page_num in range(ipFile.numPages)]
appendFile = True
filesToCombine = False
while appendFile:
ip = raw_input("Provide file along with absolute path (or) Type 'quit':\n")
if ip == 'quit':
if filesToCombine:
fh = open("output.pdf", "wb")
output.write(fh)
fh.close()
else:
print 'INFO: No files to combine'
appendFile = False
else:
if os.path.isfile(ip):
append_pdf(PdfFileReader(open(ip, "rb")))
filesToCombine = True