# PDF Form Filler A web application that allows uploading PDF forms, converting them to HTML via an LLM, and filling out the original PDFs with form data. ## Prerequisites - **Go 1.21+** - **pdftk** (for extracting form fields and filling PDFs) - **pdftoppm** (from poppler-utils, for converting PDF pages to images for the LLM) - **OpenAI API key** (or compatible LLM API) ### Installing dependencies ```bash # Ubuntu/Debian sudo apt-get install pdftk poppler-utils # macOS brew install pdftk-java poppler # Windows # pdftk: https://www.pdftk.com/ # pdftoppm: install poppler via winget or vcpkg ``` ## Configuration Set these environment variables: | Variable | Required | Description | Default | |----------|----------|-------------|---------| | `OPENAI_API_KEY` | Yes | Your OpenAI API key | - | | `OPENAI_API_URL` | No | Custom LLM API endpoint | `https://api.openai.com/v1/chat/completions` | | `OPENAI_MODEL` | No | LLM model to use | `gpt-4o` | ## Building & Running ```bash # Build go build -o pdf-form-filler . # Run ./pdf-form-filler # Or run directly OPENAI_API_KEY=your-key go run main.go ``` The server starts on `:8080` by default. ## Usage 1. Go to `http://localhost:8080/admin` 2. Upload a PDF that contains form fields 3. Click "Convert to HTML" to generate a web form using the LLM 4. Click "Open Form" to view the public form at `/form/{id}` 5. Fill out the form and submit — the filled PDF will download automatically ## Routes | Route | Method | Description | |-------|--------|-------------| | `/admin` | GET | Admin dashboard — list and manage forms | | `/admin/upload` | POST | Upload a new PDF form | | `/admin/convert` | POST | Convert a PDF to HTML via LLM | | `/admin/delete` | POST | Delete a form | | `/form/{id}` | GET | Public form page (HTML) | | `/form/{id}` | POST | Submit form — downloads filled PDF | ## How It Works 1. **Upload**: PDF is saved to the `pdfs/` directory, record created in SQLite 2. **Extract**: `pdftk dump_data_fields` extracts form field names and types 3. **Convert**: LLM receives field metadata and generates matching HTML form 4. **Fill**: On submission, form data is written to an FDF file, `pdftk fill_form` merges it with the original PDF ## Database SQLite database at `db/forms.db` — auto-created on first run.