-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmerge_pdf.py
More file actions
14 lines (10 loc) · 772 Bytes
/
Copy pathmerge_pdf.py
File metadata and controls
14 lines (10 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
from PyPDF2 import PdfWriter # Import PdfWriter class to create/merge PDF files
import os # Import os module to work with files and directories
merger = PdfWriter() # Create a PdfWriter object to merge PDFs
files = [file for file in # Create a list called 'files'
os.listdir() # Get all files/folders in the current directory
if file.endswith(".pdf")] # Keep only files that end with .pdf
for pdf in files: # Loop through each PDF file in the list
merger.append(pdf) # Add (merge) the PDF into the PdfWriter object
merger.write("merged-pdf.pdf") # Write all merged PDFs into a new file
merger.close() # Close the writer and release resources