Features
- Converts HTML to PDF using Puppeteer
- Supports custom templates for different notice types
- Runs as a service alongside the Django application
- Integrated into Docker for production deployments
Setup
Install Dependencies
Environment Configuration
Copy the example environment file:Environment Variables
| Variable | Default | Description |
|---|---|---|
DJANGO_ENV | development | Environment name |
NOTICE_SERVICE_PORT | 9229 | Port for the service |
LOG_LEVEL | info | Logging level (error, warn, info, debug) |
CHROMIUM_PATH | /usr/bin/chromium | Path to Chromium executable |
PUPPETEER_MAX_CONCURRENCY | 5 | Maximum concurrent Puppeteer instances |
Running the Service
Production
Development (with hot reloading)
API Endpoints
Health Check
Convert to PDF
- Content-Type:
application/pdf - Body: PDF file buffer
Templates
Templates are located insrc/templates. Each customer can have custom templates.
Directory Structure
Adding a New Template
- Create a directory under
src/templates/{customer_name} - Add your React component for the template
- Add any associated CSS files
- Update the template registry in
src/utils/generateTemplatePdf.ts
Configuration
All configuration is centralized inconfig.ts. The service exports helper functions:
Docker Integration
The service is integrated into the Django Docker container and runs alongside the main application. It starts automatically when the container starts.Testing
Generate Sample PDF
Manual Testing
- Start the service:
npm run dev - Send a test request:
Troubleshooting
Puppeteer Issues
If Puppeteer fails to launch:- Ensure Chromium is installed
- Check
CHROMIUM_PATHenvironment variable - On Linux, install required dependencies:
Memory Issues
If running out of memory with many concurrent requests:- Reduce
PUPPETEER_MAX_CONCURRENCY - Increase container memory limits