An intelligent PDF form auto-fill system that combines OCR, computer vision, and LLM to automatically detect form fields and fill them with provided data.
- Box Detection: Uses OpenCV to detect input fields in PDF forms
- OCR Text Extraction: Extracts labels using OCR.space API
- LLM Mapping: Uses Azure OpenAI to intelligently map JSON data to form fields
- Accurate Placement: Fixed coordinate system for precise text placement
- Multiple Field Types: Supports letter-by-letter and entire text filling
- Install Dependencies:
pip install opencv-python pdf2image pytesseract PyMuPDF requests pillow-
Configure API Keys:
- Copy
config_template.pytoconfig.py - Add your API keys:
- OCR.space API key
- Azure OpenAI API key and endpoint
- Copy
-
Run the System:
python llm_autofill_mapper.py- PDF to Image: Converts PDF to image for processing
- Field Detection: Detects input boxes using OpenCV contour detection
- OCR Extraction: Extracts text labels using OCR.space API
- LLM Mapping: Uses Azure OpenAI to map JSON data to detected fields
- Text Placement: Writes text on image using correct coordinates
- PDF Generation: Converts filled image back to PDF
output/autofilled_form.pdf- Final filled PDFoutput/filled_image.png- Filled image for verificationoutput/field_mappings.json- Complete mapping detailsoutput/detected_all_field_types.png- Visualization of detected fields
Edit config.py to customize:
- API keys and endpoints
- File paths
- Processing settings (DPI, font size, etc.)
- Python 3.7+
- OpenCV
- PyMuPDF
- OCR.space API key
- Azure OpenAI API key