The Python script demonstrates how to merge multiple PDF files found in the current directory into a single PDF document using the PyPDF2 library.
The script begins by creating a PdfWriter object named merger
from the PyPDF2 library. It then identifies all PDF files in the current directory by filtering files with the ".pdf" extension using os.listdir()
. Each PDF file is sequentially added to the merger
object using the append()
method. Once all PDFs are appended, the combined content is written to a new PDF file named "merged.pdf" using the write()
method. Finally, the merger
object is closed to release resources.
This project requires Python 3.12.1 or later. To set up the project:
-
Ensure Python 3.12.1 or a later version is installed on your system. You can download Python from python.org.
-
Clone or download the repository to your local machine.
git clone https://github.com/jaiswalchitransh/Merge-pdf-files-using-PyPDF2.git
-
Open the project in your preferred Python environment (e.g., IDE or terminal).
-
Install PyPDF2 library using pip:
pip install PyPDF2
-
Run the script (
merger.py
) and observe the output.
Run the script:
python merger.py
After execution, a file named "merged.pdf" will be created in the same directory containing the merged PDF content.
- Simple Interface: Combines PDF files with minimal configuration.
- Automatic File Detection: Identifies and merges all PDF files in the current directory.
- Efficient Resource Management: Properly closes resources after merging.
I, Chitransh Jaiswal developed this Project Individually. I was responsible for all aspects of the project, including design, development, testing, and documentation. Contributions to improve the efficiency, readability, or functionality of the code are welcome. To contribute:
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature
). - Make your changes.
- Commit your changes (
git commit -am 'Add some feature'
). - Push to the branch (
git push origin feature/your-feature
). - Create a new Pull Request.
Please ensure your contributions adhere to the coding standards and follow the existing style and structure.
Thank you for your interest in the PDF Merger using PyPDF2. Have fun Merging your PDFs!