PdfMerger is a PDF manipulation tool available both as a command-line interface (inspired by pdftk) and as a web application. Written in Python, it provides advanced features for merging, splitting, encryption, and form/attachment management.
- Features
- Requirements
- Installation
- Web Interface
- Command-Line Usage
- Exit Codes
- Known Limitations
- Differences from Original pdftk
- License
- Version
- Contributing
- Merge PDFs - Combine multiple PDF files with custom page ranges
- Split PDFs - Extract individual pages or burst into single-page files
- Encryption - Password-protect PDFs with 128-bit encryption and granular permissions
- Form Handling - Fill PDF forms using FDF data with optional flattening
- Attachments - Attach files to PDFs or extract embedded attachments
- Metadata - Read, export, and update PDF metadata
- Background - Apply background watermarks to PDF pages
- Repair - Attempt to recover corrupted PDF files
- Python 3.8 or higher
- Dependencies (see
requirements.txt):pypdf[crypto]>=3.17.1PyMuPDF>=1.23.8typing-extensions>=4.9.0
-
Clone or download the repository:
git clone <repository-url> cd PdfMerger
-
Install dependencies:
pip install -r requirements.txt
PdfMerger includes a Flask-based web interface for easy PDF merging and splitting without using the command line.
python app.pyThe server will start on http://localhost:5000 (or http://0.0.0.0:5000 for network access).
- Merge PDFs - Upload multiple PDF files and combine them into a single document
- Split PDF - Upload a single PDF and split it into individual pages (downloaded as ZIP)
- Drag & Drop - Intuitive drag-and-drop file upload
- Responsive Design - Bootstrap-styled interface that works on desktop and mobile
| Endpoint | Method | Description |
|---|---|---|
/ |
GET | Web interface homepage |
/merge |
POST | Merge multiple PDFs |
/split |
POST | Split a PDF into pages |
/download/<filename> |
GET | Download a processed file |
/cleanup |
POST | Clean up temporary files |
Merge:
curl -X POST -F "files=@file1.pdf" -F "files=@file2.pdf" http://localhost:5000/mergeSplit:
curl -X POST -F "file=@document.pdf" http://localhost:5000/split| Variable | Default | Description |
|---|---|---|
MAX_CONTENT_LENGTH |
50MB | Maximum upload size |
UPLOAD_FOLDER |
temp dir | Temporary upload location |
OUTPUT_FOLDER |
temp dir | Output file location |
python pdfmerger.py <input> [<operation>] [output <file>] [options]Combine multiple PDFs into a single file:
# Simple merge
python pdfmerger.py file1.pdf file2.pdf cat output merged.pdf
# With page ranges
python pdfmerger.py A=doc1.pdf B=doc2.pdf cat A1-3 B5-10 output result.pdf
# Pages to end
python pdfmerger.py A=doc.pdf cat A5-end output extracted.pdfSplit a PDF into individual pages:
python pdfmerger.py document.pdf burst output page_%04d.pdfCreates a doc_data.txt file with metadata.
python pdfmerger.py input.pdf dump_data output metadata.txtpython pdfmerger.py form.pdf dump_data_fields output fields.txtpython pdfmerger.py input.pdf background watermark.pdf output result.pdfpython pdfmerger.py form.pdf fill_form data.fdf output filled.pdf flattenThe flatten option flattens form fields after filling.
# Attach at document level
python pdfmerger.py input.pdf attach_files attachment1.txt attachment2.pdf output output.pdf
# Attach to a specific page
python pdfmerger.py input.pdf attach_files file.txt to_page 5 output output.pdfpython pdfmerger.py input.pdf unpack_files output ./attachments_folder/python pdfmerger.py input.pdf update_info info.json output output.pdfinfo.json format:
{
"/Title": "Document Title",
"/Author": "Author Name",
"/Subject": "Document Subject",
"/Keywords": "keyword1, keyword2",
"/Creator": "Creator Name",
"/Producer": "Producer Name"
}python pdfmerger.py input.pdf output protected.pdf encrypt_128bit owner_pw owner_password user_pw user_passwordpython pdfmerger.py input.pdf output protected.pdf encrypt_128bit allow Printing CopyContentsAvailable permissions:
Printing- Print the documentDegradedPrinting- Print at degraded qualityModifyContents- Modify document contentsAssembly- Assemble the documentCopyContents- Copy contentsScreenReaders- Screen reader accessModifyAnnotations- Modify annotationsFillIn- Fill form fieldsAllFeatures- All features enabled
| Option | Description |
|---|---|
flatten |
Flatten form fields |
compress |
Compress streams (default) |
uncompress |
Decompress streams |
verbose |
Show verbose output |
repair |
Attempt to repair corrupted PDFs |
do_ask |
Enable interactive input (default) |
dont_ask |
Disable interactive input |
python pdfmerger.py A=chapter1.pdf B=chapter2.pdf cat output book.pdf encrypt_128bit owner_pw admin user_pw reader allow Printingpython pdfmerger.py corrupted.pdf output repaired.pdf repairApply only output options to a single PDF:
python pdfmerger.py input.pdf output output.pdf flatten compress| Code | Description |
|---|---|
0 |
Success |
1 |
Error (missing input, wrong password, etc.) |
The web interface requires additional packages:
flaskflask-corswerkzeug
Install them with:
pip install flask flask-cors- The
fill_formoperation requires FDF files in simplified format backgrounduses PyMuPDF and may not preserve all interactive features- Some heavily corrupted PDFs may not be repairable
- Implemented in pure Python (with PyMuPDF support for advanced operations)
- Some FDF operations are simplified
- Native Unicode support in metadata
- Cross-platform compatibility
Free software with no warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
2.0.0 - Copyright (C) 2025
Contributions are welcome! To report bugs or request features, please open an issue.
Note: This project is not affiliated with or endorsed by the original pdftk authors.