Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PDF Batch Automator

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.

What It Does

This tool automates the entire PDF collection workflow:

  1. Fetches PDF files from configurable online repositories
  2. Handles network resilience with intelligent retry logic for transient failures
  3. Validates downloads to ensure file integrity (size checks, EOF validation)
  4. Decrypts encrypted PDFs automatically during processing
  5. Merges PDFs into single consolidated documents organized by category

Features

  • 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 to merged_pdfs/
  • File Validation: Verifies downloaded PDFs with file size checks and EOF trailer validation

Quick Start

Prerequisites

  • python 3.7+
  • virtual environment (recommended)

Installation

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.txt

Configuration

edit .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

Usage

# 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 1s

How It Works

Download Process

The tool automates this workflow:

  1. Identifies PDF URLs referenced in CBSE answer HTML pages
  2. Downloads each PDF from the server with intelligent retry strategies
  3. Validates each file (size, PDF EOF trailer)
  4. Decrypts encrypted PDFs using password from .env

Retry Strategy

  • 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

Merge Process

  1. Reads all downloaded PDFs from single_pdfs/{SUBJECT}/
  2. Decrypts encrypted PDFs using PDF_PASSWORD from .env
  3. Appends pages sequentially to merged document
  4. Saves result to merged_pdfs/{MERGED_PDF}

Technical Details

  • 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

Project Structure

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

Troubleshooting

"Missing required configuration in .env"

Ensure .env file exists with required keys: BASE_URL, OUTPUT_FOLDER, and MERGED_PDF.

"FileNotDecryptedError" during merge

Some PDFs are encrypted but decryption failed. Verify PDF_PASSWORD in .env matches the actual password.

SSL certificate errors during download

The tool disables SSL verification by default. If you see connection errors:

  1. Check internet connectivity
  2. Verify CBSE server is accessible (test with browser)
  3. The tool will retry automatically up to 40 times per file

Slow downloads / timeouts

Network instability is common with batch operations. Solutions:

  1. The tool automatically retries failed chunks—just let it run
  2. Download during off-peak hours (fewer server requests)
  3. Reduce END_SET temporarily to test smaller batches
  4. Check your internet connection stability

Dependencies

  • 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)

Performance

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)

Future Enhancements

  • 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.)

Contributing

Contributions welcome! Please:

  • Fork the repository
  • Test changes with different CBSE URLs
  • Submit pull requests with clear descriptions
  • Update documentation for new features

License

MIT License - See LICENSE file for details

Support

For issues or questions:


Professional automation tool for document collection & consolidation 📚

About

a pdf batch automator to fetch, download, and merge multiple pdf files. built this fun project for my sister who needed cbse sample papers extracted from html solution pages.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages