https://github.com/massimilianovisintainer/pdfmerger
Mmerge multiple PDF files into a single PDF using PyPDF2 library in Python
https://github.com/massimilianovisintainer/pdfmerger
pypdf2-library python
Last synced: 3 months ago
JSON representation
Mmerge multiple PDF files into a single PDF using PyPDF2 library in Python
- Host: GitHub
- URL: https://github.com/massimilianovisintainer/pdfmerger
- Owner: MassimilianoVisintainer
- Created: 2023-12-03T16:40:27.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-12-03T16:53:16.000Z (over 1 year ago)
- Last Synced: 2025-01-19T20:14:42.416Z (4 months ago)
- Topics: pypdf2-library, python
- Language: Python
- Homepage:
- Size: 1000 Bytes
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PDF Merger using PyPDF2
This script demonstrates how to merge multiple PDF files into a single PDF using PyPDF2 library in Python.
## Requirements
- Python 3.x
- PyPDF2 libraryYou can install PyPDF2 using pip:
```bash
pip install PyPDF2## Usage
1. Place the script in the directory where your PDF files are located.
2. Run the script using Python:
```bash
python pdf_merger.pyThe script will merge all the PDF files in the current directory into a single PDF file named combined.pdf.
### Code Explanation
The Python script uses PyPDF2 library to merge PDF files:
import PyPDF2
import sys
import os
merger = PyPDF2.PdfMerger()
for file in os.listdir(os.curdir):
if file.endswith(".pdf"):
merger.append(file)
merger.write("combined.pdf")The **PdfMerger object** from PyPDF2 library is used to merge multiple PDF files. It iterates through the files in the current directory and appends all files with a **.pdf** extension to the merger. Finally, it writes the merged PDF to a file named combined **.pdf**
Feel free to modify the script or adapt it according to your specific requirements.
For more information about PyPDF2 library and its functionalities, refer to the [PyPDF2 documentation](https://pypi.org/project/PyPDF2/).