Usage Guide

Quick start guide for using the Document Template Processing Service API.

Table of Contents
  1. Overview
  2. Quick Start
    1. 1. Basic Example
    2. 2. With Images
  3. API Modes
    1. Legacy Mode
    2. Enhanced Mode
  4. Documentation Sections
    1. 📋 API Endpoints
    2. 📄 Document Templates
    3. 🖼️ Image Support
    4. 🚫 Error Handling
    5. 💡 Examples
    6. 🐳 Integration Guide
  5. Base URL
  6. Health Check
  7. Main Endpoint
  8. Template Syntax Examples
    1. Variable Substitution
    2. Conditional Logic
    3. Loops
  9. Getting Started
  10. Need Help?

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

  1. 📖 Start with API Endpoints to understand the available endpoints
  2. 📄 Learn Document Templates to create your first template
  3. 💡 Try Examples for complete working examples
  4. 🚫 Reference Error Handling when troubleshooting
  5. 🖼️ Add Image Support for enhanced templates
  6. 🐳 Deploy with Integration Guide for production use

Need Help?


Copyright © 2024 Etherisc GmbH. Distributed under the MIT license.