Templates
Upload and reuse document templates (PDF, Word, Excel) to automatically fill them with data.
Overview
Templates allow you to treat documents as reusable forms. You upload a document once, and DocuDevs analyzes it to find fillable fields. You can then fill these templates repeatedly with new data via the API.
Supported Formats:
- PDF Forms: Standard AcroForms.
- Word Documents:
.docxfiles with placeholders or content controls. - Excel Spreadsheets:
.xlsxfiles. - PowerPoint Presentations:
.pptxfiles.
Managing Templates
Uploading a Template
Upload a document to create a new template. DocuDevs will automatically detect the fields available for filling.
- Python SDK
- CLI
- cURL
from docudevs.docudevs_client import DocuDevsClient
import os
import asyncio
client = DocuDevsClient(token=os.getenv('API_KEY'))
async def upload_invoice_template():
with open('invoice_template.pdf', 'rb') as f:
# Upload template with name "invoice"
response = await client.upload_template(
name="invoice",
document=f,
mime_type="application/pdf"
)
# The response contains the detected form fields
print(f"Template uploaded. Detected fields: {response.parsed.form_fields}")
# asyncio.run(upload_invoice_template())
docudevs upload-template invoice invoice_template.pdf
curl -X POST https://api.docudevs.ai/template/invoice \
-H "Authorization: Bearer $API_KEY" \
-F "document=@invoice_template.pdf"
Listing Templates
Get a list of all available templates in your organization.
- Python SDK
- CLI
- cURL
templates = await client.list_templates()
for template in templates:
print(f"Name: {template.name}, Created: {template.created_at}")
docudevs list-templates
curl -X GET https://api.docudevs.ai/template/list \
-H "Authorization: Bearer $API_KEY"
Inspecting Template Metadata
Retrieve details about a specific template, including its fillable fields.
- Python SDK
- CLI
- cURL
metadata = await client.metadata("invoice")
print(f"Fields for {metadata.name}:")
for field in metadata.form_fields:
print(f"- {field.name} ({field.type})")
docudevs template-metadata invoice
curl -X GET https://api.docudevs.ai/template/metadata/invoice \
-H "Authorization: Bearer $API_KEY"
Deleting a Template
Remove a template when it is no longer needed.
- Python SDK
- CLI
- cURL
await client.delete_template("invoice")
docudevs delete-template invoice
curl -X DELETE https://api.docudevs.ai/template/invoice \
-H "Authorization: Bearer $API_KEY"
Filling Templates
Once a template is uploaded, you can fill it with data. The data structure depends on the template type.
Filling a PDF Form
PDF forms typically use a flat dictionary of field names and values.
- Python SDK
- CLI
- cURL
from docudevs.models import TemplateFillRequest
async def fill_invoice():
fill_request = TemplateFillRequest(
fields={
"customerName": "Acme Corp",
"invoiceNumber": "INV-2024-001",
"totalAmount": "1500.00",
"paid": True
}
)
response = await client.fill(name="invoice", body=fill_request)
# Save the filled PDF
with open("filled_invoice.pdf", "wb") as f:
f.write(response.content)
# asyncio.run(fill_invoice())
# Create data.json: {"fields": {"customerName": "Acme Corp", ...}}
docudevs fill invoice data.json --output filled_invoice.pdf
curl -X POST https://api.docudevs.ai/template/fill/invoice \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"fields": {
"customerName": "Acme Corp",
"invoiceNumber": "INV-2024-001",
"totalAmount": "1500.00",
"paid": true
}
}' \
--output filled_invoice.pdf
Filling a Word Template with Tables
Word templates support nested data structures, allowing you to fill tables and repeated sections.
- Python SDK
- CLI
- cURL
async def fill_report():
fill_request = TemplateFillRequest(
fields={
"reportTitle": "Quarterly Sales",
"date": "2024-04-01",
"items": [
{"product": "Widget A", "sales": 100, "revenue": 5000},
{"product": "Widget B", "sales": 200, "revenue": 8000},
{"product": "Widget C", "sales": 50, "revenue": 2500}
],
"summary": {
"totalRevenue": 15500,
"growth": "15%"
}
}
)
response = await client.fill(name="sales_report", body=fill_request)
with open("filled_report.docx", "wb") as f:
f.write(response.content)
docudevs fill sales_report report_data.json --output filled_report.docx
curl -X POST https://api.docudevs.ai/template/fill/sales_report \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"fields": {
"reportTitle": "Quarterly Sales",
"items": [
{"product": "Widget A", "sales": 100},
{"product": "Widget B", "sales": 200}
]
}
}' \
--output filled_report.docx
Best Practices
- Field Naming: Use clear, consistent names for your form fields (e.g., camelCase like
customerName). - Testing: Upload your template and inspect the metadata to ensure all fields are detected correctly.
- Data Types: Ensure the data you send matches the expected type (e.g., booleans for checkboxes).
- Configurations: Combine templates with Named Configurations to standardize the filling process if you have complex logic.