Skip to content

Instantly share code, notes, and snippets.

@matandobr
Forked from ericmjl/merger.py
Last active November 7, 2023 06:55
Show Gist options
  • Save matandobr/d26d5b6e623531e31306daf2367b5d90 to your computer and use it in GitHub Desktop.
Save matandobr/d26d5b6e623531e31306daf2367b5d90 to your computer and use it in GitHub Desktop.
A Python script for merging PDF files together into a single PDF.
"""
Author: Eric J. Ma
Updated: Matan Dobrushin
Purpose: Merge all PDFs in the current directory together.
Install: pip install PyPDF2==3.0.1
"""
import os
from PyPDF2 import PdfReader, PdfMerger
files_dir = os.getcwd()
# Add in main text file.
pdfs = [f for f in os.listdir(files_dir) if 'pdf' in f.lower()]
# Merge the files
merger = PdfMerger()
for f in pdfs:
merger.append(PdfReader(f), 'rb')
merger.write('merged.pdf')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment