Skip to content

End-to-End Field Mapping Wizard (Backend + Frontend)#446

Open
krrishrastogi05 wants to merge 2 commits intofireform-core:mainfrom
krrishrastogi05:feat/field-wizard-frontend
Open

End-to-End Field Mapping Wizard (Backend + Frontend)#446
krrishrastogi05 wants to merge 2 commits intofireform-core:mainfrom
krrishrastogi05:feat/field-wizard-frontend

Conversation

@krrishrastogi05
Copy link
Copy Markdown

@krrishrastogi05 krrishrastogi05 commented Apr 16, 2026

Summary

This PR implements the complete Field Mapping Wizard (#111), enabling users to upload a PDF, automatically detect all form fields, and create a template in a single flow.

It includes:

  • Backend PDF field detection engine
  • Frontend Wizard UI
  • One-click template creation workflow

This reduces template setup time from manual effort (~30 minutes) to a few seconds.


Problem

Creating templates from fillable PDFs currently requires:

  1. Manually inspecting each field in the PDF
  2. Copying field names
  3. Writing a JSON mapping
  4. Handling errors manually

This becomes inefficient and error-prone for PDFs with many fields.


Solution

A unified wizard that:

  1. Accepts a PDF upload
  2. Detects all form fields automatically
  3. Displays them in the UI
  4. Allows instant template creation

###Screenshots and Videos

Screenshot 2026-04-16 125347 Screenshot 2026-04-16 124121

Key Features

Backend: Field Detection API

  • Endpoint: POST /wizard/detect-fields

  • Extracts:

    • Field name
    • Field type (Text, Button, Choice)
    • Raw PDF type
    • Bounding box coordinates
  • Returns structured, page-wise metadata

  • Built using pypdf

Example response:

{
  "filename": "fire_response_report.pdf",
  "total_pages": 1,
  "total_fields": 50,
  "pages": [
    {
      "page_number": 1,
      "fields": [
        {
          "field_name": "Incident_Report_Number",
          "field_type": "Text",
          "raw_type": "/Tx",
          "rect": { "x": 72.0, "y": 660.0, "width": 150.0, "height": 18.0 }
        }
      ]
    }
  ]
}

Frontend: Field Wizard UI

  • New “Field Wizard” tab
  • Drag-and-drop PDF upload
  • Field detection trigger
  • Visual display grouped by page
  • Type-based field labeling

One-Click Template Creation

  • Converts detected fields into JSON mapping
  • Auto-generates template name from filename
  • Transfers PDF to template upload
  • Pre-fills template creation form

User only needs to submit the form.


Implementation Details

Backend

  • src/field_detector.py: Field extraction logic
  • src/controller.py: Detection integration
  • api/routes/wizard.py: API endpoint
  • api/schemas/wizard.py: Response models
  • tests/test_wizard.py: Test coverage
  • requirements.txt: Added pypdf

Frontend

  • frontend/index.html: Wizard UI
  • frontend/styles.css: Layout and styling
  • frontend/app.js: API integration and workflow logic

Relation to Existing Code

  • Reuses PDF parsing logic from src/filler.py
  • Refactors it into a reusable detection module
  • Extends it with structured output and API exposure

Limitations

  • Supports only fillable PDFs (AcroForms)
  • Scanned/image PDFs return no fields
  • No OCR support
  • No AI dependency

How to Test

Backend

python -m pytest tests/test_wizard.py -v

Run API:

python -m uvicorn api.main:app --reload --port 8000

Frontend

cd frontend
python -m http.server 5173

Open:
http://127.0.0.1:5173

Flow:

  1. Upload PDF
  2. Detect fields
  3. Use as template

Future Work

  • Visual PDF canvas with field overlays
  • Drag-and-drop schema mapping
  • Field renaming
  • OCR for scanned PDFs
  • AI-based field mapping

Closes Phase 1 and 2 of #111

…ireform-core#111)

Introduce PDFFieldDetector class that parses PDF /Annots annotations
to extract interactive form field metadata (name, type, bounding box).

Changes:
- Add src/field_detector.py with PDFFieldDetector class
- Add api/routes/wizard.py with POST /wizard/detect-fields endpoint
- Add api/schemas/wizard.py with Pydantic response models
- Update src/controller.py to delegate to PDFFieldDetector
- Update api/main.py to register wizard router
- Add pypdf to requirements.txt (was imported but not listed)
- Add tests/test_wizard.py with comprehensive test coverage

Supported field types: Text (/Tx), Button (/Btn), Choice (/Ch)
Returns structured JSON with field coordinates for frontend rendering.

Note: Only digitally created fillable PDFs (AcroForms) are supported.
Scanned/image-based PDFs would require OCR as a future enhancement.

Closes fireform-core#111 (Phase 1)
…re#111)

Add a new 'Field Wizard' tab to the frontend that lets users upload
a PDF and instantly see all detected fillable form fields.

Changes:
- frontend/index.html: Add wizard tab, dropzone, detect button, results area
- frontend/styles.css: Color-coded type badges (Text/Button/Choice),
  field cards, summary bar, loading spinner, responsive layout
- frontend/app.js: Wizard file handling, API integration with
  /wizard/detect-fields, dynamic result rendering grouped by page

The UI follows the existing tab-based panel pattern and reuses
shared utilities (setStatus, formatBytes, isPdfFile, parseJsonResponse).

Depends on: feat/pdf-field-detection-engine (backend PR)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant