A simple Python script to merge two PDF files into one.
- Merge two PDF files in sequential order
- Custom output path or automatic naming with timestamp
- Validates input files before processing
- Clear error messages and progress feedback
- Saves to Desktop by default when no output path is specified
- Clone or download this repository
- Install the required dependencies:
pip3 install -r requirements.txtOr install PyPDF2 directly:
pip3 install PyPDF2python3 ./src/main.py <PDF1> <PDF2> [--out OUTPUT_PATH]Merge with custom output path:
python3 ./src/main.py document1.pdf document2.pdf --out merged.pdfMerge with automatic naming (saves to Desktop):
python3 ./src/main.py document1.pdf document2.pdfThis creates a file named document1_document2_YYYYMMDD_HHMMSS.pdf on your Desktop.
Using short option flag:
python3 ./src/main.py report.pdf appendix.pdf -o final_report.pdfpdf1- Path to the first PDF file (required)pdf2- Path to the second PDF file (required)--out, -o- Output path for the merged PDF (optional)
- With
--outflag: Saves to the specified path - Without
--outflag: Saves to Desktop with format{PDF1_name}_{PDF2_name}_{timestamp}.pdf - The script creates output directories if they don't exist
The script will exit with an error message if:
- Input PDF files don't exist
- Files cannot be read or merged
- Write permissions are insufficient
- Python 3.x
- PyPDF2
This project is open source and available for use.