A robust, professional-grade automation tool for batch-downloading and consolidating PDF documents from online repositories. Designed to automate repetitive document collection workflows with intelligent retry logic, file validation, and merge capabilities.
This tool automates the entire PDF collection workflow:
- Fetches PDF files from configurable online repositories
- Handles network resilience with intelligent retry logic for transient failures
- Validates downloads to ensure file integrity (size checks, EOF validation)
- Decrypts encrypted PDFs automatically during processing
- Merges PDFs into single consolidated documents organized by category
- Configurable Subject Selection: Easily switch between subjects (Maths, Science, English, Hindi, etc.) via
.env - Resilient Download Engine: Handles unreliable server connections with exponential backoff and chunked resumable downloads
- Professional Progress Tracking: Real-time progress bars with ETA for downloads and merging
- Encrypted PDF Support: Automatically decrypts password-protected PDFs
- Organized Output: Saves individual PDFs to
single_pdfs/{subject}/and merged results tomerged_pdfs/ - File Validation: Verifies downloaded PDFs with file size checks and EOF trailer validation
- python 3.7+
- virtual environment (recommended)
git clone https://github.com/th3-w41k3r5/pdf-batch-automator.git
cd pdf-batch-automator
# create and activate virtual environment
python -m venv .venv
.\.venv\Scripts\Activate.ps1 # windows
source .venv/bin/activate # macos/linux
# install dependencies
pip install -r requirements.txtedit .env to select your repository:
# Required: CBSE answer paper URL
BASE_URL=https://cbse.online/sample-papers-2026/class-10/english-language/answers
# Required: Output folder name (no spaces)
OUTPUT_FOLDER=english_pdfs
# Required: Merged PDF filename
MERGED_PDF=English_Sets_1_to_30.pdf
# Optional: Customize set range
START_SET=1
END_SET=30
# Optional: Folder configuration
SINGLE_PDFS_FOLDER=single_pdfs
MERGED_PDFS_FOLDER=merged_pdfs
MERGE_PDFS=True
# Optional: PDF password for decryption
PDF_PASSWORD=Durgra01042025Pinepage2025$Example Configurations:
- Maths:
BASE_URL=https://cbse.online/sample-papers-2026/class-10/maths-standard/answers+OUTPUT_FOLDER=maths_pdfs - Science:
BASE_URL=https://cbse.online/sample-papers-2026/class-10/science/answers+OUTPUT_FOLDER=science_pdfs
# Download and merge (configured in .env)
python app.py
# Expected output:
# [01] Downloading... OK
# [02] Downloading... OK
# ...
# Downloading sets: 100%|████████| 30/30 [00:58<00:00, 1.96s/file]
# ✅ Download complete. Files saved to: single_pdfs\english_pdfs
# 🗂 Merging all PDFs into one…
# Merging: 100%|████████████| 30/30 [00:00<00:00, 60.08file/s]
# ✅ Merged 30 PDFs → merged_pdfs\English_Sets_1_to_30.pdf
# ⏱️ Time: 0m 1sThe tool automates this workflow:
- Identifies PDF URLs referenced in CBSE answer HTML pages
- Downloads each PDF from the server with intelligent retry strategies
- Validates each file (size, PDF EOF trailer)
- Decrypts encrypted PDFs using password from
.env
- Session-level: 10 retries with 1.5x exponential backoff for HTTP 429/5xx errors
- Per-chunk: 12 retries for Range-request chunks (256KB each)
- Per-file: Up to 40 total attempts before marking as failed
- Resilience: Handles transient SSL/network failures gracefully
- Reads all downloaded PDFs from
single_pdfs/{SUBJECT}/ - Decrypts encrypted PDFs using
PDF_PASSWORDfrom.env - Appends pages sequentially to merged document
- Saves result to
merged_pdfs/{MERGED_PDF}
- Uses HTTP Range headers for efficient resumable downloads (256KB chunks)
- Falls back to streaming if Range requests aren't supported
- Validates file integrity: checks file size and PDF EOF trailer (
%%EOF) - SSL verification disabled to work with internal CBSE servers
pdf-batch-automator/
├── .env # Configuration (BASE_URL, OUTPUT_FOLDER, etc.)
├── .gitignore # Git ignore patterns
├── README.md # This file
├── requirements.txt # Python dependencies
├── app.py # Main downloader + merger
├── single_pdfs/ # Individual PDFs organized by subject
│ ├── english_pdfs/
│ ├── maths_pdfs/
│ └── science_pdfs/
└── merged_pdfs/ # Merged PDF outputs
├── English_Sets_1_to_30.pdf
├── Maths_Merged_All_30_Sets.pdf
└── Science_Merged_All_30_Sets.pdf
Ensure .env file exists with required keys: BASE_URL, OUTPUT_FOLDER, and MERGED_PDF.
Some PDFs are encrypted but decryption failed. Verify PDF_PASSWORD in .env matches the actual password.
The tool disables SSL verification by default. If you see connection errors:
- Check internet connectivity
- Verify CBSE server is accessible (test with browser)
- The tool will retry automatically up to 40 times per file
Network instability is common with batch operations. Solutions:
- The tool automatically retries failed chunks—just let it run
- Download during off-peak hours (fewer server requests)
- Reduce
END_SETtemporarily to test smaller batches - Check your internet connection stability
- requests (2.32.5+): HTTP client with retry/backoff support
- PyPDF2 (3.0.1+): PDF reading, decryption, merging
- tqdm (4.67.1+): Progress bars with ETA
Optional:
- pdfkit (1.0.0+): HTML-to-PDF conversion (not actively used)
Typical performance on stable network:
- Download: ~1.5–2 seconds per 300–500 KB PDF
- Merge: ~60 PDFs/second
- Total time for 30 sets: 45–60 seconds (download) + 1 second (merge)
- Support for class 11/12 papers
- Multi-subject concurrent downloads
- Web UI for easier configuration
- Email notifications on completion
- Support for other educational platforms (ICSE, IB, etc.)
Contributions welcome! Please:
- Fork the repository
- Test changes with different CBSE URLs
- Submit pull requests with clear descriptions
- Update documentation for new features
MIT License - See LICENSE file for details
For issues or questions:
- Check Troubleshooting section
- Review existing GitHub issues
- Verify CBSE server status at cbse.online
Professional automation tool for document collection & consolidation 📚