Usage Guide
Quick start guide for using the Document Template Processing Service API.
Table of Contents
Overview
The Document Template Processing Service converts Word document templates with data injection into PDF files. It uses Jinja2 templating syntax and supports both simple text substitution and advanced features like images, loops, and conditional logic.
Quick Start
1. Basic Example
Template (template.docx):
Customer:
Amount: $
API Request:
curl -X POST http://localhost:8000/api/v1/process-template-document \
-F "file=@template.docx" \
-F "data={\"customer_name\":\"John Doe\",\"amount\":150.00}" \
-o result.pdf
2. With Images
Template (template.docx):
Company Logo:
Customer:
API Request:
curl -X POST http://localhost:8000/api/v1/process-template-document \
-F "file=@template.docx" \
-F "request_data={\"template_data\":{\"customer_name\":\"John Doe\",\"company_logo\":\"\"},\"images\":{\"logo\":{\"data\":\"base64_data\",\"width_mm\":40}}}" \
-o result.pdf
API Modes
The service supports two usage modes through a single unified endpoint:
Legacy Mode
- Parameter:
data
(JSON object) - Use case: Simple templates without images
- Benefit: Backward compatible with existing integrations
Enhanced Mode
- Parameter:
request_data
(JSON string) - Use case: Templates with images and complex data structures
- Benefit: Support for inline images and React-friendly format
Documentation Sections
📋 API Endpoints
Complete API reference with parameters, responses, and examples for all endpoints.
📄 Document Templates
Learn how to create Word templates with Jinja2 syntax, including:
- Variable substitution
- Conditional logic (if/else)
- Loops (for each)
- Advanced template patterns
- Best practices and troubleshooting
🖼️ Image Support
Comprehensive guide to including images in templates:
- Base64 encoding for React applications
- Size specifications and optimization
- Template integration examples
- Troubleshooting image issues
🚫 Error Handling
Understanding and debugging errors:
- HTTP status codes and error types
- Structured error responses
- Common issues and solutions
- Debugging strategies
💡 Examples
Complete practical examples:
- Invoice generation with complex data
- React and Node.js integration code
- Postman testing setup
- Real-world use cases
🐳 Integration Guide
Docker Compose setup and integration patterns for existing applications.
Base URL
- Local:
http://localhost:8000
- Docker:
http://document-templating-service:8000
(within Docker network)
Health Check
GET /
or /health-check
{
"status": "Service is healthy !"
}
Main Endpoint
POST /api/v1/process-template-document
Parameters:
file
: Word document template (.docx)data
: JSON object (legacy mode)request_data
: JSON string with template_data and images (enhanced mode)
Response: PDF file download
Template Syntax Examples
Variable Substitution
Hello , your order total is $.
Conditional Logic
{% if premium_customer %}
Thank you for being a premium customer!
{% else %}
Thank you for your business!
{% endif %}
Loops
Order Items:
{% for item in items %}
- {{item.name}}: ${{item.price}}
{% endfor %}
Getting Started
- 📖 Start with API Endpoints to understand the available endpoints
- 📄 Learn Document Templates to create your first template
- 💡 Try Examples for complete working examples
- 🚫 Reference Error Handling when troubleshooting
- 🖼️ Add Image Support for enhanced templates
- 🐳 Deploy with Integration Guide for production use
Need Help?
- Check the Error Handling guide for common issues
- Try the Examples for working code samples
- Review the Document Templates guide for syntax help
- Use the API Endpoints reference for parameter details