Created
July 4, 2013 08:37
-
-
Save absolutelyNoWarranty/5925982 to your computer and use it in GitHub Desktop.
Join a bunch of pdfs (like chapters of a book) into one pdf.
This file contains 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
from pyPdf import PdfFileReader, PdfFileWriter | |
import sys, os | |
if len(sys.argv)>1: | |
output_name = sys.argv[1] | |
else: | |
output_name = "all.pdf" | |
pdfs = filter(lambda f: os.path.splitext(f)[1]=='.pdf', os.walk(".").next()[2]) | |
pdfs.sort() | |
print pdfs | |
# join them all together | |
output = PdfFileWriter() | |
for fname in pdfs: | |
pdf = PdfFileReader(file(fname, "rb")) | |
for page in range(pdf.getNumPages()): | |
output.addPage(pdf.getPage(page)) | |
output.write(file(output_name, "wb")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment