A lightweight Python utility for effortlessly merging multiple PDF files into a single document.
- ๐ Description
- ๐ Repository Structure
- ๐ป Installation
- ๐ฎ Usage
- ๐ ๏ธ Development
- ๐ค Contributing
- ๐จโ๐ป Author
- ๐ License
- ๐ Star History
- ๐ Acknowledgments
PDFusion is a simple yet powerful command-line tool that makes it easy to combine multiple PDF files into a single document while preserving the original quality. Perfect for combining reports, consolidating documentation, or organizing digital paperwork.
- ๐ Merge all PDFs in a directory with a single command
- ๐ Automatic alphabetical ordering of files
- โฑ๏ธ Timestamp-based output naming option
- ๐ ๏ธ Both CLI and Python API support
- ๐ก Clear progress feedback and error handling
- ๐ Maintains original PDF quality
- ๐ Detailed logging of the merge process
- ๐ Type hints with full mypy support
- ๐งช Comprehensive test coverage (>90%)
- ๐ Performance benchmarks included
- ๐ Custom exception handling
- ๐ฏ Supports Python 3.11+
graph TD
A[pdfusion/] --> B[pdfusion/]
A --> C[tests/]
A --> D[examples/]
A --> E[Documentation]
B --> B1[__init__.py]
B --> B2[exceptions.py]
B --> B3[logging.py]
B --> B4[pdfusion.py]
B --> B5[py.typed]
C --> C1[__init__.py]
C --> C2[conftest.py]
C --> C3[test files]
D --> D1[basic_usage.py]
E --> E1[README.md]
E --> E2[LICENSE]
E --> E3[CONTRIBUTING.md]
E --> E4[Configuration Files]
pip install pdfusion
graph LR
A[Clone Repository] --> B[Create Virtual Environment]
B --> C[Activate Environment]
C --> D[Install Dependencies]
D --> E[Ready to Develop!]
-
Clone the repository:
git clone https://github.com/BjornMelin/pdfusion.git cd pdfusion
-
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: .\venv\Scripts\activate
Note: You can also use
virtualenv
instead ofvenv
. See the Virtual Environment Setup Guide for more details. -
Install development dependencies:
pip install -r requirements-dev.txt
-
Install PDFusion
pip install pdfusion
-
Prepare Your PDFs
-
Create a directory with your PDF files
-
Example structure:
my_pdfs/ โโโ document1.pdf โโโ document2.pdf โโโ document3.pdf
-
-
Run PDFusion
graph LR
A[Input Directory] --> B[PDFusion CLI]
B --> C[Processing]
C --> D[Merged PDF]
style B fill:#f9f,stroke:#333,stroke-width:4px
# Basic usage
pdfusion /path/to/pdfs -o merged.pdf
# With verbose output
pdfusion /path/to/pdfs -v
# Auto timestamp filename
pdfusion /path/to/pdfs
-o, --output
: Output filename (optional)-v, --verbose
: Enable verbose output--version
: Show version number-h, --help
: Show help message
from pdfusion import merge_pdfs
# Example 1: Basic usage
result = merge_pdfs(
input_dir="/path/to/pdfs",
output_file="merged.pdf"
)
print(f"Merged {result.files_merged} files into {result.output_path}")
# Example 2: With verbose output and auto timestamp
result = merge_pdfs(
input_dir="/path/to/pdfs",
verbose=True
)
print(f"Total pages in merged PDF: {result.total_pages}")
# Example 3: Full options
result = merge_pdfs(
input_dir="/path/to/pdfs",
output_file="merged.pdf",
verbose=True,
sort_files=True, # Sort files alphabetically
add_bookmarks=True # Add bookmarks for each merged PDF
)
Create a simple script merge_my_pdfs.py
:
from pdfusion import merge_pdfs
import logging
# Set up logging (optional)
logging.basicConfig(level=logging.INFO)
# Merge PDFs
try:
result = merge_pdfs(
input_dir="./my_pdfs",
output_file="merged_document.pdf",
verbose=True
)
print(f"Successfully merged {result.files_merged} files!")
print(f"Output saved to: {result.output_path}")
print(f"Total pages: {result.total_pages}")
except Exception as e:
print(f"Error merging PDFs: {e}")
Run your script:
python merge_my_pdfs.py
The merge_pdfs
function returns a result object with the following attributes:
files_merged
: Number of files mergedoutput_path
: Path to the merged PDFtotal_pages
: Total number of pages in the merged PDFprocessing_time
: Time taken to merge the PDFs
# Run all tests
pytest
# Run with coverage report
pytest --cov=pdfusion
# Run performance benchmarks
pytest tests/test_pdfusion.py -v -m benchmark
# Run specific test file
pytest tests/test_pdfusion.py -v
graph LR
A[Fork Repository] --> B[Create Feature Branch]
B --> C[Make Changes]
C --> D[Commit Changes]
D --> E[Push to Branch]
E --> F[Open Pull Request]
style F fill:#f96,stroke:#333,stroke-width:4px
- Fork the repository
- Create your feature branch (
git checkout -b feat/version/AmazingFeature
) - Commit your changes (
git commit -m 'type(scope): Add some AmazingFeature'
) - Push to the branch (
git push origin feat/version/AmazingFeature
) - Open a Pull Request (
feat(scope): Add some AmazingFeature
)
AWS-certified Solutions Architect and Developer with expertise in cloud architecture and modern development practices. Connect with me on:
Project Link: https://github.com/BjornMelin/pdfusion
This project is licensed under the MIT License - see the LICENSE file for details.
- ๐ Python
- ๐ pypdf2
- ๐ท๏ธ GitHub Badges