Introduction
Theedit method in Retab’s document processing pipeline enables intelligent PDF form filling. It automatically detects form fields in any PDF document using OCR and LLM inference, then fills them based on natural language instructions. This is ideal for automating form completion workflows, document generation, and batch processing of standardized forms.
The edit workflow follows these steps:
- OCR Processing: Extract text elements with precise bounding box coordinates
- Form Field Detection: Use LLM to identify fillable fields (text inputs, checkboxes)
- Intelligent Filling: Match your instructions to the appropriate form fields
- PDF Generation: Create a new PDF with the filled values
edit provides:
- Zero Configuration: No need to pre-define field positions or create templates
- Natural Language Instructions: Describe what to fill in plain English
- Automatic Field Matching: LLM intelligently maps your data to form fields
- MIMEData Output: Get the filled PDF as MIMEData with filename and base64 content
- Checkbox Support: Handles both text fields and checkboxes
Edit API
An EditResponse object containing the filled PDF and form data.
Use Case: Automated Form Filling
Fill PDF forms programmatically using natural language instructions.Use Case: Batch Form Processing
Process multiple forms with different data programmatically.Best Practices
Model Selection
gemini-2.5-pro: Most accurate for complex forms with many fields or ambiguous layouts. Recommended for production use.gemini-2.5-flash: Faster and more cost-effective, suitable for simple forms with clear field labels.
Annotation Level Selection
line(default): Best for most standard forms where fields are organized in rowsblock: Better for forms with dense text or multi-line field descriptionstoken: Use when you need precise word-level detection for tightly packed forms
Writing Effective Filling Instructions
- Be explicit: Use field labels that match or closely resemble those in the form
- Use key-value pairs: Format as “Field Name: Value” for best matching
- For checkboxes: Use “checked” or “unchecked” as the value
- Include context: If a form has multiple similar fields, add context like “Section A - Name: John”
Working with MIMEData
- The
filled_pdfresponse is a MIMEData object withfilenameandurlproperties - The
urlis a data URI:data:application/pdf;base64,<base64_content> - Extract base64 content by splitting on comma:
url.split(",")[1] - Python SDK accepts file paths directly and handles MIMEData conversion automatically