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
- Java 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
import ai.docudevs.client.DocuDevsClient;
import ai.docudevs.client.UploadRequest;
import java.nio.file.Files;
import java.nio.file.Path;
DocuDevsClient client = DocuDevsClient.builder()
.apiKey(System.getenv("API_KEY"))
.build();
byte[] fileBytes = Files.readAllBytes(Path.of("invoice_template.pdf"));
UploadRequest upload = new UploadRequest("invoice_template.pdf", "application/pdf", fileBytes);
client.uploadTemplate("invoice", upload);
System.out.println("Template uploaded.");
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
- Java SDK
- CLI
- cURL
templates = await client.list_templates()
for template in templates:
print(f"Name: {template.name}, Created: {template.created_at}")
docudevs list-templates
import ai.docudevs.client.DocuDevsClient;
import com.fasterxml.jackson.databind.JsonNode;
DocuDevsClient client = DocuDevsClient.builder()
.apiKey(System.getenv("API_KEY"))
.build();
JsonNode templates = client.listTemplates();
for (JsonNode template : templates) {
System.out.println(template.path("name").asText() + " created=" + template.path("createdAt").asText());
}
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
- Java 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
import ai.docudevs.client.DocuDevsClient;
import com.fasterxml.jackson.databind.JsonNode;
DocuDevsClient client = DocuDevsClient.builder()
.apiKey(System.getenv("API_KEY"))
.build();
JsonNode metadata = client.getTemplateMetadata("invoice");
for (JsonNode field : metadata) {
System.out.println(field.path("name").asText() + " (" + field.path("type").asText() + ")");
}
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
- Java SDK
- CLI
- cURL
await client.delete_template("invoice")
docudevs delete-template invoice
import ai.docudevs.client.DocuDevsClient;
DocuDevsClient client = DocuDevsClient.builder()
.apiKey(System.getenv("API_KEY"))
.build();
client.deleteTemplate("invoice");
System.out.println("Deleted 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
- Java 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
import ai.docudevs.client.DocuDevsClient;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
DocuDevsClient client = DocuDevsClient.builder()
.apiKey(System.getenv("API_KEY"))
.build();
byte[] filled = client.fillTemplate("invoice", Map.of(
"customerName", "Acme Corp",
"invoiceNumber", "INV-2024-001",
"totalAmount", "1500.00",
"paid", true
));
Files.write(Path.of("filled_invoice.pdf"), filled);
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
- Java 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
import ai.docudevs.client.DocuDevsClient;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
DocuDevsClient client = DocuDevsClient.builder()
.apiKey(System.getenv("API_KEY"))
.build();
byte[] filled = client.fillTemplate("sales_report", Map.of(
"reportTitle", "Quarterly Sales",
"date", "2024-04-01",
"items", List.of(
Map.of("product", "Widget A", "sales", 100, "revenue", 5000),
Map.of("product", "Widget B", "sales", 200, "revenue", 8000),
Map.of("product", "Widget C", "sales", 50, "revenue", 2500)
),
"summary", Map.of("totalRevenue", 15500, "growth", "15%")
));
Files.write(Path.of("filled_report.docx"), filled);
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.