from retab import Retab
client = Retab()
# Edit the form by inferring fields and filling them
result = client.documents.edit(
document="form.pdf", # Can be a file path, URL, or MIMEData
filling_instructions="Name: John Doe, Date of Birth: 1990-01-15, Address: 123 Main Street, City: New York",
model="gemini-2.5-pro",
)
# Access the filled PDF (MIMEData with filename and url containing base64 data)
if result.filled_pdf:
import base64
# Extract base64 content from data URI
base64_content = result.filled_pdf.url.split(",")[1]
filled_pdf_bytes = base64.b64decode(base64_content)
with open("filled_form.pdf", "wb") as f:
f.write(filled_pdf_bytes)
# Access form data with filled values
print(f"Filled {len(result.form_data)} form fields")
for field in result.form_data:
print(f"Field: {field.description} = {field.value}")
{
"form_data": [
{
"bbox": {
"left": 0.15,
"top": 0.20,
"width": 0.35,
"height": 0.03,
"page": 1
},
"description": "Full Name - text input field for applicant's legal name",
"type": "text",
"value": "John Doe"
},
{
"bbox": {
"left": 0.15,
"top": 0.28,
"width": 0.20,
"height": 0.03,
"page": 1
},
"description": "Date of Birth - date field in MM/DD/YYYY format",
"type": "text",
"value": "01/15/1990"
},
{
"bbox": {
"left": 0.55,
"top": 0.45,
"width": 0.02,
"height": 0.02,
"page": 1
},
"description": "Agreement checkbox - confirms acceptance of terms",
"type": "checkbox",
"value": "unchecked"
}
],
"filled_pdf": {
"filename": "filled_form.pdf",
"url": "data:application/pdf;base64,JVBERi0xLjQK..."
}
}
Edit a PDF document by inferring form fields and filling them with provided instructions.
This endpoint redirects to the internal edit service’s infer_and_fill_schema endpoint. It performs:
from retab import Retab
client = Retab()
# Edit the form by inferring fields and filling them
result = client.documents.edit(
document="form.pdf", # Can be a file path, URL, or MIMEData
filling_instructions="Name: John Doe, Date of Birth: 1990-01-15, Address: 123 Main Street, City: New York",
model="gemini-2.5-pro",
)
# Access the filled PDF (MIMEData with filename and url containing base64 data)
if result.filled_pdf:
import base64
# Extract base64 content from data URI
base64_content = result.filled_pdf.url.split(",")[1]
filled_pdf_bytes = base64.b64decode(base64_content)
with open("filled_form.pdf", "wb") as f:
f.write(filled_pdf_bytes)
# Access form data with filled values
print(f"Filled {len(result.form_data)} form fields")
for field in result.form_data:
print(f"Field: {field.description} = {field.value}")
{
"form_data": [
{
"bbox": {
"left": 0.15,
"top": 0.20,
"width": 0.35,
"height": 0.03,
"page": 1
},
"description": "Full Name - text input field for applicant's legal name",
"type": "text",
"value": "John Doe"
},
{
"bbox": {
"left": 0.15,
"top": 0.28,
"width": 0.20,
"height": 0.03,
"page": 1
},
"description": "Date of Birth - date field in MM/DD/YYYY format",
"type": "text",
"value": "01/15/1990"
},
{
"bbox": {
"left": 0.55,
"top": 0.45,
"width": 0.02,
"height": 0.02,
"page": 1
},
"description": "Agreement checkbox - confirms acceptance of terms",
"type": "checkbox",
"value": "unchecked"
}
],
"filled_pdf": {
"filename": "filled_form.pdf",
"url": "data:application/pdf;base64,JVBERi0xLjQK..."
}
}
from retab import Retab
client = Retab()
# Edit the form by inferring fields and filling them
result = client.documents.edit(
document="form.pdf", # Can be a file path, URL, or MIMEData
filling_instructions="Name: John Doe, Date of Birth: 1990-01-15, Address: 123 Main Street, City: New York",
model="gemini-2.5-pro",
)
# Access the filled PDF (MIMEData with filename and url containing base64 data)
if result.filled_pdf:
import base64
# Extract base64 content from data URI
base64_content = result.filled_pdf.url.split(",")[1]
filled_pdf_bytes = base64.b64decode(base64_content)
with open("filled_form.pdf", "wb") as f:
f.write(filled_pdf_bytes)
# Access form data with filled values
print(f"Filled {len(result.form_data)} form fields")
for field in result.form_data:
print(f"Field: {field.description} = {field.value}")
{
"form_data": [
{
"bbox": {
"left": 0.15,
"top": 0.20,
"width": 0.35,
"height": 0.03,
"page": 1
},
"description": "Full Name - text input field for applicant's legal name",
"type": "text",
"value": "John Doe"
},
{
"bbox": {
"left": 0.15,
"top": 0.28,
"width": 0.20,
"height": 0.03,
"page": 1
},
"description": "Date of Birth - date field in MM/DD/YYYY format",
"type": "text",
"value": "01/15/1990"
},
{
"bbox": {
"left": 0.55,
"top": 0.45,
"width": 0.02,
"height": 0.02,
"page": 1
},
"description": "Agreement checkbox - confirms acceptance of terms",
"type": "checkbox",
"value": "unchecked"
}
],
"filled_pdf": {
"filename": "filled_form.pdf",
"url": "data:application/pdf;base64,JVBERi0xLjQK..."
}
}
Request for the infer_and_fill_schema endpoint.
Instructions to fill the form
LLM model to use for inference
Successful Response
Response from the fill_form endpoint.
The OCR results used for inference
Show child attributes
Human-readable formatted string of all elements
All detected text elements
Show child attributes
The detected text content
Bounding box in normalized coordinates
Show child attributes
Left coordinate of the bounding box, relative to page width (0.0 = left edge, 1.0 = right edge).
Top coordinate of the bounding box, relative to page height (0.0 = top edge, 1.0 = bottom edge).
Width of the bounding box, relative to page width (0.0–1.0).
Height of the bounding box, relative to page height (0.0–1.0).
1-based index of the page where this field appears in the processed document.
Type of element: 'block', 'line', or 'token'
List of form fields (with positions, descriptions, and metadata) that define the structure of the form.
Show child attributes
Bounding box specifying the position and size of this field on the page.
Show child attributes
Left coordinate of the bounding box, relative to page width (0.0 = left edge, 1.0 = right edge).
Top coordinate of the bounding box, relative to page height (0.0 = top edge, 1.0 = bottom edge).
Width of the bounding box, relative to page width (0.0–1.0).
Height of the bounding box, relative to page height (0.0–1.0).
1-based index of the page where this field appears in the processed document.
Human-readable description of the field, including its label, section, and instructions for how it should be filled.
Type of field. Currently supported values: 'text' and 'checkbox'.
text, checkbox Filled value of the field as text. May be null/None if no filled value is set.