Skip to content

Instantly share code, notes, and snippets.

@reuf
Created September 30, 2015 09:08
Show Gist options
  • Save reuf/cb97eb1a4e37d3cb2ba2 to your computer and use it in GitHub Desktop.
Save reuf/cb97eb1a4e37d3cb2ba2 to your computer and use it in GitHub Desktop.
Combine PDF Files in current working dir into one
# 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