Created
December 27, 2016 21:58
-
-
Save frvannes16/e974ff3f15cb1972ae72e25a5d166dc2 to your computer and use it in GitHub Desktop.
PDF file merge
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
| """ | |
| Author: Franklin van Nes | |
| Purpose: To merge all PDFs in a directory together in an automated fashion. | |
| """ | |
| import os | |
| from PyPDF2 import PdfFileReader, PdfFileMerger | |
| files_dir = os.getcwd() | |
| print(os.listdir(files_dir)) | |
| all_files = [f for f in os.listdir(files_dir) if '.pdf' in f] | |
| # Merge the files | |
| merger = PdfFileMerger() | |
| for f in all_files: | |
| merger.append(PdfFileReader(f), 'rb') | |
| merger.write('merged_pdf.pdf') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment