Skip to content

feat: Add inline image support to document templates#1

Merged
christoph2806 merged 2 commits intomasterfrom
feature/image-support
Aug 2, 2025
Merged

feat: Add inline image support to document templates#1
christoph2806 merged 2 commits intomasterfrom
feature/image-support

Conversation

@christoph2806
Copy link
Copy Markdown

🖼️ Image Support Implementation

This PR adds comprehensive inline image support to the Document Template Processing Service, enabling embedding of PNG images directly in Word document templates.

Key Features

  • 🎯 New API Endpoint:
  • 📱 React-Friendly: Base64 image encoding in JSON payloads
  • 📏 Flexible Sizing: Support for both millimeters (print) and pixels (web)
  • 🔧 Template Integration: Simple Jinja2 syntax like {{ company_logo }}
  • 🛡️ Error Handling: Comprehensive image processing error management
  • 🔄 Backward Compatible: Original endpoint remains unchanged

🚀 Implementation Highlights

  • Leverages docxtpl's InlineImage functionality
  • Pydantic models for structured request validation
  • Automatic DPI conversion (96px = 25.4mm)
  • Temporary file management with proper cleanup
  • Comprehensive test suite with automated validation

📋 API Example

{
  "template_data": {
    "customer_name": "John Doe",
    "logo": "{{company_logo}}"
  },
  "images": {
    "company_logo": {
      "data": "base64_encoded_png_data",
      "width_mm": 50,
      "height_mm": 20
    }
  }
}

📚 Documentation Added

  • Image Support Guide - Complete implementation guide
  • React integration examples with hooks
  • cURL examples and troubleshooting
  • Best practices for image optimization

Testing

  • ✅ Image processing with Base64 encoding
  • ✅ PDF generation with embedded images
  • ✅ Multiple image support
  • ✅ Backward compatibility maintained
  • ✅ Comprehensive error handling validated

🔧 Files Changed

  • main.py - Core image processing implementation
  • docs/image-support.md - New comprehensive documentation
  • test_image_support.py - Automated test suite
  • requirements-test.txt - Added Pillow for testing
  • Updated navigation in README.md, docs/README.md, index.md

Ready for review and testing! 🚀

- Add new endpoint /api/v1/process-template-document-with-images
- Support Base64 encoded PNG images with flexible sizing (mm/px)
- Implement comprehensive image processing with error handling
- Add Pydantic models for structured image data validation
- Maintain backward compatibility with original endpoint
- Add comprehensive documentation in docs/image-support.md
- Include React integration examples and best practices
- Add test script with automated validation of image functionality
- Update all documentation links and navigation
- Clean up old test files and improve test organization

This implementation leverages docxtpl's InlineImage capabilities
and provides the most React-friendly API using Base64 encoding
within JSON payloads for seamless frontend integration.
- Add image endpoint documentation to usage guide
- Include image template syntax and examples
- Update API examples in index.md to show both endpoints
- Add Node.js and Python examples with images to integration guide
- Ensure all documentation references both original and image-enhanced endpoints
- Maintain comprehensive coverage of new image capabilities
@christoph2806 christoph2806 merged commit 94eae7b into master Aug 2, 2025
1 check passed
@christoph2806 christoph2806 deleted the feature/image-support branch August 2, 2025 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant