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": {
"left": 0.16,
"top": 0.22,
"width": 0.34,
"height": 0.03,
"page": 1
},
"value": null
},
{
"key": "date_of_birth",
"description": "Applicant's date of birth",
"type": "date",
"bbox": {
"left": 0.16,
"top": 0.27,
"width": 0.18,
"height": 0.03,
"page": 1
},
"value": null
},
{
"key": "email_address",
"description": "Contact email address",
"type": "text",
"bbox": {
"left": 0.16,
"top": 0.32,
"width": 0.29,
"height": 0.03,
"page": 1
},
"value": null
},
{
"key": "signature",
"description": "Applicant signature",
"type": "signature",
"bbox": {
"left": 0.14,
"top": 0.78,
"width": 0.28,
"height": 0.07,
"page": 1
},
"value": null
},
{
"key": "agree_to_terms",
"description": "Checkbox to agree to terms and conditions",
"type": "checkbox",
"bbox": {
"left": 0.07,
"top": 0.72,
"width": 0.02,
"height": 0.02,
"page": 1
},
"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": {
"left": 0.16,
"top": 0.22,
"width": 0.34,
"height": 0.03,
"page": 1
},
"value": null
},
{
"key": "date_of_birth",
"description": "Applicant's date of birth",
"type": "date",
"bbox": {
"left": 0.16,
"top": 0.27,
"width": 0.18,
"height": 0.03,
"page": 1
},
"value": null
},
{
"key": "email_address",
"description": "Contact email address",
"type": "text",
"bbox": {
"left": 0.16,
"top": 0.32,
"width": 0.29,
"height": 0.03,
"page": 1
},
"value": null
},
{
"key": "signature",
"description": "Applicant signature",
"type": "signature",
"bbox": {
"left": 0.14,
"top": 0.78,
"width": 0.28,
"height": 0.07,
"page": 1
},
"value": null
},
{
"key": "agree_to_terms",
"description": "Checkbox to agree to terms and conditions",
"type": "checkbox",
"bbox": {
"left": 0.07,
"top": 0.72,
"width": 0.02,
"height": 0.02,
"page": 1
},
"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": {
"left": 0.16,
"top": 0.22,
"width": 0.34,
"height": 0.03,
"page": 1
},
"value": null
},
{
"key": "date_of_birth",
"description": "Applicant's date of birth",
"type": "date",
"bbox": {
"left": 0.16,
"top": 0.27,
"width": 0.18,
"height": 0.03,
"page": 1
},
"value": null
},
{
"key": "email_address",
"description": "Contact email address",
"type": "text",
"bbox": {
"left": 0.16,
"top": 0.32,
"width": 0.29,
"height": 0.03,
"page": 1
},
"value": null
},
{
"key": "signature",
"description": "Applicant signature",
"type": "signature",
"bbox": {
"left": 0.14,
"top": 0.78,
"width": 0.28,
"height": 0.07,
"page": 1
},
"value": null
},
{
"key": "agree_to_terms",
"description": "Checkbox to agree to terms and conditions",
"type": "checkbox",
"bbox": {
"left": 0.07,
"top": 0.72,
"width": 0.02,
"height": 0.02,
"page": 1
},
"value": null
}
]
},
"annotated_pdf": {
"filename": "blank_form_annotated.pdf",
"mime_type": "application/pdf",
"url": "data:application/pdf;base64,JVBERi0xLjQK..."
},
"field_count": 5
}