A powerful web application built with Flask that allows users to merge multiple PDF files and edit existing PDFs by removing or inserting pages. Features a clean, modern interface with easy-to-use tools for all your PDF needs.
- Multiple PDF Upload: Upload and merge 2-50 PDF files at once
- Large File Support: Handle PDFs up to 100MB per file (500MB total)
- Duplicate File Support: Upload the same PDF file multiple times in different positions
- Flexible Ordering: Files are merged in the order they are uploaded
- Progress Indicators: Real-time upload and merge progress tracking
- Chunked Upload: Optimized handling for large files
- Download Merged PDF: Get your combined PDF instantly
- Page Preview: View all pages as thumbnails before editing
- Large PDF Support: Edit PDFs up to 100MB with optimized loading
- Remove Pages: Click the "- Remove" button to delete unwanted pages
- Insert Pages: Click the "+ Insert After" button to add new PDF pages at any position
- Drag & Drop Reordering: Rearrange pages by dragging them
- Multiple Insertions: Insert multiple PDF files at different positions
- Visual Feedback: See which pages are marked for removal in real-time
- Progress Tracking: Visual progress for uploads and edits
- Download Edited PDF: Get your modified PDF with all changes applied
- Clean Design: Professional, light-colored interface without gradients
- Responsive Layout: Works perfectly on desktop, tablet, and mobile devices
- Help System: Built-in help button (?) with detailed usage instructions
- Easy Navigation: Back buttons on every page for seamless navigation
- Progress Bars: Real-time visual feedback for all operations
- File Size Validation: Automatic checking of file sizes before upload
- Success Pages: Clear confirmation pages after operations complete
- Error Handling: User-friendly error messages with helpful guidance
pdf-merger/
βββ api/
β βββ app.py # Main Flask application with all routes
βββ templates/
β βββ index.html # Home page with feature selection and help
β βββ upload.html # File upload interface for merging
β βββ result.html # Success page for merged PDFs
β βββ upload_for_edit.html # PDF upload page for editing
β βββ edit_pages.html # Page editor with preview and controls
β βββ edit_success.html # Success page for edited PDFs
βββ uploads/ # Temporary upload directory
βββ merged/ # Output directory for merged files
βββ edit_sessions/ # Temporary storage for editing sessions
βββ requirements.txt # Python dependencies
βββ vercel.json # Vercel deployment configuration
βββ LICENSE # MIT License
βββ README.md # This file
-
Clone the repository:
git clone <repository-url> cd pdf-merger
-
Create a virtual environment:
python -m venv venv
-
Activate the virtual environment:
- Windows:
venv\Scripts\activate
- macOS/Linux:
source venv/bin/activate
- Windows:
-
Install dependencies:
pip install -r requirements.txt
-
Run the application:
python api/app.py
-
Access the application: Open your browser and navigate to
http://localhost:5000
The application requires the following Python packages:
- Flask: Web framework for building the application
- PyPDF2: Library for PDF manipulation and merging
- PyMuPDF (fitz): High-performance PDF rendering for page previews
- Pillow: Python Imaging Library for image processing
- Werkzeug: WSGI utility library (included with Flask)
- Select Feature: Click "π Merge Multiple PDFs" on the home page
- Enter Count: Specify how many PDF files you want to merge (2-50)
- Upload Files: Select PDF files for each slot
- You can upload the same file multiple times if needed
- Files will be merged in the order of the slots
- Merge: Click "Merge PDFs" to combine them
- Download: Download your merged PDF or start a new merge
- Select Feature: Click "βοΈ Edit PDF (Remove/Insert Pages)" on the home page
- Upload PDF: Select the PDF file you want to edit
- View Pages: All pages will be displayed as thumbnails
- Remove Pages:
- Click the "- Remove" button on any page to mark it for removal
- Click again to undo the removal
- Insert Pages:
- Click the "+ Insert After" button on any page
- Upload one or more PDF files to insert at that position
- You can insert at multiple positions
- Apply Changes: Click "Apply Changes & Download"
- Download: Download your edited PDF
- Click the "?" button in the top-right corner of the home page
- Read the detailed instructions for each feature
- Learn tips and best practices
GET /: Home page with feature selectionPOST /: Process file count and redirect to upload pagePOST /merge: Handle PDF file uploads and mergingGET /download: Download the merged PDF fileGET /restart: Return to the home page for a new merge
GET /edit-mode: Show PDF upload page for editingPOST /process-upload-for-edit: Process uploaded PDF and create editing sessionGET /page-image/<session_id>/<page_num>: Generate and serve page preview imagesPOST /apply-edits: Apply page removals and insertionsGET /download-edited/<session_id>: Download the edited PDF file
The application is configured for Vercel deployment using the vercel.json configuration file:
{
"version": 2,
"builds": [
{
"src": "api/app.py",
"use": "@vercel/python"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "api/app.py"
}
]
}To deploy on Vercel:
-
Install Vercel CLI:
npm i -g vercel
-
Deploy:
vercel
-
Follow the prompts to configure your deployment
- Merging: Uploaded files stored in
/tmp/uploads, merged files in/tmp/merged - Editing: Session-based storage in
/tmp/edit_sessionswith unique session IDs - Auto Cleanup: All uploaded files are automatically deleted after processing
- Unique Filenames: UUID-based naming prevents conflicts when uploading duplicate files
- Chunked Processing: Large files processed in 8KB chunks for memory efficiency
- Session Cleanup: Edit sessions automatically cleaned up after download
- Merging: Uses PyPDF2's
PdfMergerandPdfWriterfor efficient combining - Page Extraction: PyPDF2's
PdfReaderfor page-level manipulation - Image Rendering: PyMuPDF (fitz) renders PDF pages as JPEG thumbnails
- Optimization: 0.8x zoom and 60% JPEG quality for fast loading of large PDFs
- Large File Handling: Optimized processing for PDFs up to 100MB
- Progressive Loading: Adaptive delay based on PDF size (200-250ms per page)
- File Validation: Only PDF files accepted with size limits (100MB per file, 500MB total)
- Size Checking: Pre-upload validation prevents oversized files
- Session Isolation: Each editing session has a unique ID with sanitized filenames
- Directory Traversal Protection: All filenames sanitized using
secure_filename() - No Persistent Storage: Files deleted immediately after download
- Progressive Loading: Page images load sequentially to avoid server overload
- Error Recovery: Retry mechanism for failed page loads with user-friendly messages
- Serverless Ready: Optimized for Vercel's serverless functions with 500MB limit
- Memory Management: Chunked file reading/writing for large files
- Modern CSS: Clean, professional design without gradients
- Responsive Grid: Adapts to any screen size
- Smooth Animations: Fade-in effects and hover transitions
- Custom Scrollbars: Styled scrollbars for better UX
- Modal System: Help popup with keyboard shortcuts (ESC to close)
- Lazy Loading: Progressive image loading for better performance
- File Count: Maximum 50 PDFs can be merged at once
- File Size: 100MB per individual file, 500MB total for merging
- Processing Time: Large PDFs may take longer to process in serverless environments
- Page Previews: Generated on-demand with progressive loading for better performance
- No Password Support: Cannot process password-protected PDFs
- Temporary Storage: Files are not permanently stored, download immediately
- No Encryption: Edited/merged PDFs are not encrypted
- Serverless Timeout: Very large operations may timeout on some hosting platforms
Potential features for future development:
- Password-protected PDF support
- Page rotation functionality
- Page reordering (drag and drop)
- PDF compression options
- Watermark addition
- PDF to image conversion
- Batch processing
- Cloud storage integration
Contributions are welcome! To contribute:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Flask - Web framework
- PyPDF2 - PDF manipulation library
- PyMuPDF - Fast PDF rendering
- Vercel - Deployment platform
If you encounter any issues or have questions:
- Open an issue on GitHub
- Check the built-in help (? button) on the website
Live Demo: https://pdf-merger-eta-rust.vercel.app/