Papersmith
An AI-powered PDF renamer that uses OpenAI's models (e.g., gpt-4o, gpt-4.1) via the /v1/responses API to intelligently rename PDF documents based on their content. Papersmith analyzes your PDFs by sending them directly to the API and generates descriptive filenames that include the document date, category, and title.
How It Works
- Papersmith reads each PDF file specified by the glob pattern.
- The raw PDF data is base64 encoded.
- This encoded data is sent directly to the OpenAI
/v1/responsesAPI along with a prompt asking for document details. - The AI extracts key information like dates, document categories, and suggested titles.
- A standardized filename is generated in the format:
YYYYMMDD-title-category.pdf. - The PDF is renamed according to this format.
- This process is idempotent, as Papersmith will not rename files that already match the expected format (
^\d{8}.*\.pdf$).
Installation
Application Setup
-
Ensure you have Rust installed (rustup.rs).
-
Clone this repository.
-
Create a
.envfile in the project root with your OpenAI API key:PAPERSMITH_OPENAI_API_KEY=your_api_key_here -
You can also set a default glob pattern for PDF files in the
.envfile:PAPERSMITH_GLOB_PATTERN="./my_pdfs/**/*.pdf"If
PAPERSMITH_GLOB_PATTERNis not set or the command-line argument--glob-patternis not provided, the application will an error.
Usage
# Basic usage (processes PDFs based on PAPERSMITH_GLOB_PATTERN or an error if not set)
# Process PDFs in a specific directory (overrides PAPERSMITH_GLOB_PATTERN if set)
# Preview changes without renaming files
# Specify a compatible OpenAI model (e.g., gpt-4o, gpt-4.1)
Command Line Options
-g, --glob-pattern <PATTERN>: Glob pattern to specify which PDFs to process. If not provided,PAPERSMITH_GLOB_PATTERNfrom the.envfile is used. If neither is set, it's an error.-m, --model <MODEL>: Choose the OpenAI model to use (default: "gpt-4o-mini", but ensure the chosen model is compatible with the/v1/responsesendpoint for direct PDF processing, likegpt-4oorgpt-4.1).-d, --dry-run: Preview changes without renaming files.-h, --help: Display help information.-V, --version: Display version information.
For example:
Scanned Document 1.pdf→20240916-bunnings-invoice.pdfDocument.pdf→20231225-unknown-document.pdf
Building
Run these commands in the project root directory:
# Debug build
# Release build
License
This project is open source and available under the MIT License.