Skip to main content
POST
/
v1
/
edit
/
templates
/
generate
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
}
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
}

Authorizations

Api-Key
string
header
required

Query Parameters

access_token
string | null

Body

application/json

Request to infer form schema from a PDF or DOCX document.

document
MIMEData · object
required

Input document (PDF, DOCX, XLSX or PPTX).

model
string
default:retab-small

LLM model to use for inference

Response

Successful Response

Response from the FFDNet + LLM hybrid form schema inference.

form_schema
FormSchema · object
required

Form schema with FFDNet bboxes and LLM-assigned names

annotated_pdf
MIMEData · object
required

PDF with form field bounding boxes

field_count
integer
required

Number of fields detected by FFDNet