129 lines
3.8 KiB
Markdown
129 lines
3.8 KiB
Markdown
# PDF Rename Sort
|
|
|
|
A Python web application built with Flask that automatically renames PDF files based on form field data extracted from within the PDFs. Designed for batch processing of fillable PDFs, extracting "Last Name" and "First Name" to create standardized filenames.
|
|
|
|
## Features
|
|
|
|
- **Web-Based Interface**: Clean, responsive web UI for easy file uploads
|
|
- **Batch Processing**: Handle multiple PDFs or ZIP archives containing PDFs
|
|
- **Form Field Extraction**: Uses PyPDF2 to read PDF form fields
|
|
- **Intelligent Renaming**: Renames files to "LastName_FirstName.pdf" format
|
|
- **Duplicate Handling**: Automatically appends counters for duplicate names
|
|
- **ZIP Support**: Upload ZIP files and download processed results as ZIP
|
|
- **Error Handling**: Gracefully skips files that can't be processed
|
|
|
|
## Prerequisites
|
|
|
|
- Python 3.6 or higher
|
|
- Virtual environment (recommended)
|
|
- Microsoft Entra ID (Azure AD) tenant with app registration
|
|
|
|
## Microsoft Entra ID Setup
|
|
|
|
**Detailed setup instructions**: See [ENTRA_SETUP.md](ENTRA_SETUP.md) for comprehensive step-by-step guide to configure Microsoft Entra ID authentication.
|
|
|
|
### Quick Setup:
|
|
1. Register application in Azure Portal (optional for admin login)
|
|
2. Get Tenant ID, Client ID, and Client Secret (for Entra login)
|
|
3. Set environment variables:
|
|
```bash
|
|
# For Entra ID login (optional)
|
|
export TENANT_ID="your-tenant-id"
|
|
export CLIENT_ID="your-client-id"
|
|
export CLIENT_SECRET="your-client-secret"
|
|
|
|
# For admin login
|
|
export ADMIN_USERNAME="trbcit"
|
|
export ADMIN_PASSWORD="atdrmbicn"
|
|
|
|
# Required
|
|
export SECRET_KEY="your-random-secret-key"
|
|
```
|
|
|
|
## Authentication
|
|
|
|
The application supports two authentication methods:
|
|
|
|
1. **Microsoft Entra ID**: OAuth2 authentication with Azure AD
|
|
2. **Admin Login**: Local username/password authentication
|
|
|
|
Users can choose their preferred login method on the login page.
|
|
|
|
## Installation
|
|
|
|
1. **Clone the repository**:
|
|
```bash
|
|
git clone https://gitlab.com/trbc-dev/pdf-rename-sort.git
|
|
cd pdf-rename-sort
|
|
```
|
|
|
|
2. **Create and activate virtual environment**:
|
|
```bash
|
|
python -m venv .venv
|
|
# On Windows:
|
|
& .venv/Scripts/Activate.ps1
|
|
# On macOS/Linux:
|
|
source .venv/bin/activate
|
|
```
|
|
|
|
3. **Install dependencies**:
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
## Usage
|
|
|
|
1. **Set environment variables** (see Entra ID Setup above)
|
|
|
|
2. **Run the application**:
|
|
```bash
|
|
python pdf_renamer.py
|
|
```
|
|
|
|
3. **Access the web interface**:
|
|
- Open `http://127.0.0.1:3000/`
|
|
- You'll be redirected to Microsoft login
|
|
- After authentication, you'll access the app
|
|
|
|
4. **Upload files**:
|
|
- Select individual PDF files or ZIP archives containing PDFs
|
|
- Click "Process PDFs"
|
|
|
|
5. **Download results**:
|
|
- Download the `renamed_files.zip` containing all processed PDFs
|
|
- Review any skipped files listed on the results page
|
|
|
|
## How It Works
|
|
|
|
1. **File Upload**: Accepts PDFs or ZIPs via web form
|
|
2. **Extraction**: If ZIP, extracts PDFs to temporary directory
|
|
3. **Processing**: For each PDF, reads form fields using PyPDF2
|
|
4. **Renaming**: Extracts "Last Name" and "First Name" values
|
|
5. **Packaging**: Creates a ZIP archive of renamed PDFs
|
|
6. **Download**: Provides secure download link for results
|
|
|
|
## Important Notes
|
|
|
|
- PDFs must contain fillable form fields named exactly "Last Name" and "First Name"
|
|
- Files without these fields or with extraction errors will be skipped
|
|
- All processing happens server-side with temporary file storage
|
|
- Maximum upload size is limited to 100MB
|
|
|
|
## Development
|
|
|
|
To contribute or modify:
|
|
|
|
1. Fork the repository
|
|
2. Create a feature branch
|
|
3. Make your changes
|
|
4. Test thoroughly
|
|
5. Submit a pull request
|
|
|
|
## License
|
|
|
|
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
|
|
## Support
|
|
|
|
For issues or questions, please open an issue on the GitLab repository.
|