from retab import Retab
import base64
client = Retab()
# Generate form schema from a PDF document
response = client.edit.templates.generate(
document="blank_form.pdf",
model="retab-small"
)
print(f"Detected {response.field_count} fields")
# Access the form schema
for field in response.form_schema.form_fields:
print(f"Field: {field.key} - {field.description} ({field.type})")
# Save the annotated PDF (with bounding boxes drawn)
if response.annotated_pdf:
pdf_bytes = base64.b64decode(response.annotated_pdf.url.split(",")[1])
with open("annotated_form.pdf", "wb") as f:
f.write(pdf_bytes)
{
"form_schema": {
"form_fields": [
{
"key": "full_name",
"description": "Full legal name of the applicant",
"type": "text",
"bbox": {
"page": 0,
"x": 120,
"y": 185,
"width": 250,
"height": 22
},
value: null
},
{
"key": "date_of_birth",
"description": "Applicant's date of birth",
"type": "date",
"bbox": {
"page": 0,
"x": 120,
"y": 220,
"width": 120,
"height": 22
},
value: null
},
{
"key": "email_address",
"description": "Contact email address",
"type": "text",
"bbox": {
"page": 0,
"x": 120,
"y": 255,
"width": 200,
"height": 22
},
value: null
},
{
"key": "signature",
"description": "Applicant signature",
"type": "signature",
"bbox": {
"page": 0,
"x": 100,
"y": 650,
"width": 200,
"height": 50
},
value: null
},
{
"key": "agree_to_terms",
"description": "Checkbox to agree to terms and conditions",
"type": "checkbox",
"bbox": {
"page": 0,
"x": 50,
"y": 600,
"width": 15,
"height": 15
},
value: null
}
]
},
"annotated_pdf": {
"filename": "blank_form_annotated.pdf",
"mime_type": "application/pdf",
"url": "data:application/pdf;base64,JVBERi0xLjQK..."
},
"field_count": 5
}
Infer form schema from a PDF document.
This endpoint combines:
Supported document formats:
Returns:
form_schema: The detected form schema with field keys, descriptions, types, and bounding boxesannotated_pdf: PDF with bounding boxes drawn around detected fields for visual verificationdetection_count: Number of fields detectedfrom retab import Retab
import base64
client = Retab()
# Generate form schema from a PDF document
response = client.edit.templates.generate(
document="blank_form.pdf",
model="retab-small"
)
print(f"Detected {response.field_count} fields")
# Access the form schema
for field in response.form_schema.form_fields:
print(f"Field: {field.key} - {field.description} ({field.type})")
# Save the annotated PDF (with bounding boxes drawn)
if response.annotated_pdf:
pdf_bytes = base64.b64decode(response.annotated_pdf.url.split(",")[1])
with open("annotated_form.pdf", "wb") as f:
f.write(pdf_bytes)
{
"form_schema": {
"form_fields": [
{
"key": "full_name",
"description": "Full legal name of the applicant",
"type": "text",
"bbox": {
"page": 0,
"x": 120,
"y": 185,
"width": 250,
"height": 22
},
value: null
},
{
"key": "date_of_birth",
"description": "Applicant's date of birth",
"type": "date",
"bbox": {
"page": 0,
"x": 120,
"y": 220,
"width": 120,
"height": 22
},
value: null
},
{
"key": "email_address",
"description": "Contact email address",
"type": "text",
"bbox": {
"page": 0,
"x": 120,
"y": 255,
"width": 200,
"height": 22
},
value: null
},
{
"key": "signature",
"description": "Applicant signature",
"type": "signature",
"bbox": {
"page": 0,
"x": 100,
"y": 650,
"width": 200,
"height": 50
},
value: null
},
{
"key": "agree_to_terms",
"description": "Checkbox to agree to terms and conditions",
"type": "checkbox",
"bbox": {
"page": 0,
"x": 50,
"y": 600,
"width": 15,
"height": 15
},
value: null
}
]
},
"annotated_pdf": {
"filename": "blank_form_annotated.pdf",
"mime_type": "application/pdf",
"url": "data:application/pdf;base64,JVBERi0xLjQK..."
},
"field_count": 5
}
from retab import Retab
import base64
client = Retab()
# Generate form schema from a PDF document
response = client.edit.templates.generate(
document="blank_form.pdf",
model="retab-small"
)
print(f"Detected {response.field_count} fields")
# Access the form schema
for field in response.form_schema.form_fields:
print(f"Field: {field.key} - {field.description} ({field.type})")
# Save the annotated PDF (with bounding boxes drawn)
if response.annotated_pdf:
pdf_bytes = base64.b64decode(response.annotated_pdf.url.split(",")[1])
with open("annotated_form.pdf", "wb") as f:
f.write(pdf_bytes)
{
"form_schema": {
"form_fields": [
{
"key": "full_name",
"description": "Full legal name of the applicant",
"type": "text",
"bbox": {
"page": 0,
"x": 120,
"y": 185,
"width": 250,
"height": 22
},
value: null
},
{
"key": "date_of_birth",
"description": "Applicant's date of birth",
"type": "date",
"bbox": {
"page": 0,
"x": 120,
"y": 220,
"width": 120,
"height": 22
},
value: null
},
{
"key": "email_address",
"description": "Contact email address",
"type": "text",
"bbox": {
"page": 0,
"x": 120,
"y": 255,
"width": 200,
"height": 22
},
value: null
},
{
"key": "signature",
"description": "Applicant signature",
"type": "signature",
"bbox": {
"page": 0,
"x": 100,
"y": 650,
"width": 200,
"height": 50
},
value: null
},
{
"key": "agree_to_terms",
"description": "Checkbox to agree to terms and conditions",
"type": "checkbox",
"bbox": {
"page": 0,
"x": 50,
"y": 600,
"width": 15,
"height": 15
},
value: null
}
]
},
"annotated_pdf": {
"filename": "blank_form_annotated.pdf",
"mime_type": "application/pdf",
"url": "data:application/pdf;base64,JVBERi0xLjQK..."
},
"field_count": 5
}
Successful Response
Response from the FFDNet + LLM hybrid form schema inference.