Skip to content

Instantly share code, notes, and snippets.

@luanfonceca
Created October 7, 2013 02:46
Show Gist options
  • Save luanfonceca/6861852 to your computer and use it in GitHub Desktop.
Save luanfonceca/6861852 to your computer and use it in GitHub Desktop.
Python code to concatenate PDF files, just keep them ordered by name, like pdf_01, pdf_02, pdf_10...
from pyPdf import PdfFileWriter, PdfFileReader
import os
def append_pdf(input, output):
[output.addPage(input.getPage(page_num)) \
for page_num in range(input.numPages)]
output = PdfFileWriter()
for pdf in filter(lambda x: '.pdf' in x, os.listdir('.')):
append_pdf(PdfFileReader(file(pdf, "rb")), output)
output.write(file("final.pdf", "wb"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment