from retab import Retab
import base64
client = Retab()
# Fill a form using a pre-defined template
response = client.edit.templates.fill(
template_id="edittplt_abc123",
instructions="""
Full Name: Jane Smith
Date of Birth: March 15, 1985
Email: jane.smith@example.com
Phone: (555) 123-4567
""",
model="retab-small"
)
print(f"Filled {len(response.form_data)} fields")
# Save the filled PDF
if response.filled_document:
pdf_bytes = base64.b64decode(response.filled_document.url.split(",")[1])
with open("filled_form.pdf", "wb") as f:
f.write(pdf_bytes)
print("Filled form saved!")
{
"form_data": [
{
"key": "full_name",
"description": "Full name of the applicant",
"type": "text",
"value": "Jane Smith",
"bbox": {
"page": 1,
"left": 0.15,
"top": 0.25,
"width": 0.35,
"height": 0.025
}
},
{
"key": "date_of_birth",
"description": "Date of birth",
"type": "date",
"value": "March 15, 1985",
"bbox": {
"page": 1,
"left": 0.15,
"top": 0.30,
"width": 0.20,
"height": 0.025
}
},
{
"key": "email",
"description": "Email address",
"type": "text",
"value": "jane.smith@example.com",
"bbox": {
"page": 1,
"left": 0.15,
"top": 0.35,
"width": 0.35,
"height": 0.025
}
},
{
"key": "phone",
"description": "Phone number",
"type": "text",
"value": "(555) 123-4567",
"bbox": {
"page": 1,
"left": 0.15,
"top": 0.40,
"width": 0.25,
"height": 0.025
}
}
],
"filled_document": {
"filename": "filled_form.pdf",
"mime_type": "application/pdf",
"url": "data:application/pdf;base64,JVBERi0xLjQK..."
}
}
from retab import Retab
import base64
client = Retab()
# Fill a form using a pre-defined template
response = client.edit.templates.fill(
template_id="edittplt_abc123",
instructions="""
Full Name: Jane Smith
Date of Birth: March 15, 1985
Email: jane.smith@example.com
Phone: (555) 123-4567
""",
model="retab-small"
)
print(f"Filled {len(response.form_data)} fields")
# Save the filled PDF
if response.filled_document:
pdf_bytes = base64.b64decode(response.filled_document.url.split(",")[1])
with open("filled_form.pdf", "wb") as f:
f.write(pdf_bytes)
print("Filled form saved!")
{
"form_data": [
{
"key": "full_name",
"description": "Full name of the applicant",
"type": "text",
"value": "Jane Smith",
"bbox": {
"page": 1,
"left": 0.15,
"top": 0.25,
"width": 0.35,
"height": 0.025
}
},
{
"key": "date_of_birth",
"description": "Date of birth",
"type": "date",
"value": "March 15, 1985",
"bbox": {
"page": 1,
"left": 0.15,
"top": 0.30,
"width": 0.20,
"height": 0.025
}
},
{
"key": "email",
"description": "Email address",
"type": "text",
"value": "jane.smith@example.com",
"bbox": {
"page": 1,
"left": 0.15,
"top": 0.35,
"width": 0.35,
"height": 0.025
}
},
{
"key": "phone",
"description": "Phone number",
"type": "text",
"value": "(555) 123-4567",
"bbox": {
"page": 1,
"left": 0.15,
"top": 0.40,
"width": 0.25,
"height": 0.025
}
}
],
"filled_document": {
"filename": "filled_form.pdf",
"mime_type": "application/pdf",
"url": "data:application/pdf;base64,JVBERi0xLjQK..."
}
}
from retab import Retab
import base64
client = Retab()
# Fill a form using a pre-defined template
response = client.edit.templates.fill(
template_id="edittplt_abc123",
instructions="""
Full Name: Jane Smith
Date of Birth: March 15, 1985
Email: jane.smith@example.com
Phone: (555) 123-4567
""",
model="retab-small"
)
print(f"Filled {len(response.form_data)} fields")
# Save the filled PDF
if response.filled_document:
pdf_bytes = base64.b64decode(response.filled_document.url.split(",")[1])
with open("filled_form.pdf", "wb") as f:
f.write(pdf_bytes)
print("Filled form saved!")
{
"form_data": [
{
"key": "full_name",
"description": "Full name of the applicant",
"type": "text",
"value": "Jane Smith",
"bbox": {
"page": 1,
"left": 0.15,
"top": 0.25,
"width": 0.35,
"height": 0.025
}
},
{
"key": "date_of_birth",
"description": "Date of birth",
"type": "date",
"value": "March 15, 1985",
"bbox": {
"page": 1,
"left": 0.15,
"top": 0.30,
"width": 0.20,
"height": 0.025
}
},
{
"key": "email",
"description": "Email address",
"type": "text",
"value": "jane.smith@example.com",
"bbox": {
"page": 1,
"left": 0.15,
"top": 0.35,
"width": 0.35,
"height": 0.025
}
},
{
"key": "phone",
"description": "Phone number",
"type": "text",
"value": "(555) 123-4567",
"bbox": {
"page": 1,
"left": 0.15,
"top": 0.40,
"width": 0.25,
"height": 0.025
}
}
],
"filled_document": {
"filename": "filled_form.pdf",
"mime_type": "application/pdf",
"url": "data:application/pdf;base64,JVBERi0xLjQK..."
}
}
Request for the fill endpoint. Uses pre-defined form fields from the template (PDF only)
Instructions to fill the form
Template ID to use for filling. When provided, uses the template's pre-defined form fields and empty PDF. Only works for PDF documents. Mutually exclusive with document.
LLM model to use for inference
Configuration for the fill request
Show child attributes