Created
July 15, 2020 13:33
-
-
Save danperrout/1fa3a714541bd5b96a876a09556448c6 to your computer and use it in GitHub Desktop.
Merge two or more PDF with Python - Easy and simple
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
# Merging two or more PDF files | |
# Install PyPDF2 with pip | |
# ´pip install PyPDF2´ | |
# Save this file on the folder and run it on the terminal with ´python merge.py´ | |
import glob | |
from PyPDF2 import PdfFileMerger | |
def merger(output_path, input_paths): | |
pdf_merger = PdfFileMerger() | |
file_handles = [] | |
for path in input_paths: | |
pdf_merger.append(path) | |
with open(output_path, 'wb') as fileobj: | |
pdf_merger.write(fileobj) | |
if __name__ == '__main__': | |
paths = glob.glob('*.pdf') | |
paths.sort() | |
merger('output.pdf', paths) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment