Created
September 30, 2015 09:08
-
-
Save reuf/cb97eb1a4e37d3cb2ba2 to your computer and use it in GitHub Desktop.
Combine PDF Files in current working dir into one
This file contains hidden or 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
# Loading the pyPdf Library | |
from pyPdf import PdfFileWriter, PdfFileReader | |
import os | |
from os import listdir | |
# Creating a routine that appends files to the output file | |
def append_pdf(input,output): | |
[output.addPage(input.getPage(page_num)) for page_num in range(input.numPages)] | |
# Creating an object where pdf pages are appended to | |
output = PdfFileWriter() | |
all_pdfs = [ f for f in listdir(os.getcwd()) if f.endswith(".pdf") ] | |
for pdf_file in all_pdfs: | |
print(pdf_file) | |
append_pdf(PdfFileReader(file(pdf_file,"rb")),output) | |
output.write(file("SveZajedno.pdf","wb")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment