Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! python3
- # combinePdfs.py - Combines all the PDFs in the current working directory into
- # a single PDF.
- import PyPDF2, os
- # Get all the PDF filenames.
- pdfFiles = []
- for filename in os.listdir('.'):
- if filename.endswith('.pdf'):
- pdfFiles.append(filename)
- pdfWriter = PyPDF2.PdfFileWriter()
- # Loop through all the PDF files.
- for filename in pdfFiles:
- pdfFileObj = open(filename, 'rb')
- pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
- # password of each PDF file is below
- pdfReader.decrypt('mtgy')
- # Loop through all the pages (except the first) and add them.
- for pageNum in range(0, 0):
- pageObj = pdfReader.getPage(pageNum)
- pdfWriter.addPage(pageObj)
- # Save the resulting PDF to a file.
- pdfOutput = open('consolidat.pdf', 'wb')
- pdfWriter.write(pdfOutput)
- pdfOutput.close()
Add Comment
Please, Sign In to add comment