> ## Documentation Index
> Fetch the complete documentation index at: https://docs.khanhng.com/llms.txt
> Use this file to discover all available pages before exploring further.

# AD-004 Render reports from HTML to PDF

> AD-004 Render reports from HTML to PDF for ReportGeneratorTool.

**Status:** Accepted **Decision date:** 2025-08-01 **Implementation:** Confirmed in the repository at commit `27045ec`.

## Context and decision drivers

The report combines client branding, device details, calculated temperature metrics, alarm information, and a chart. The layout must be customizable to a client's design system. The service already uses Chromium for portal automation.

## Options considered

| Option | Assessment at decision time |
| - | - |
| HTML and CSS rendered to PDF with Puppeteer | Supports the required layout and reuses the browser capability already selected for the workflow. |
| Third-party PDF generator | Would add cost and an integration point, with less control over styling. |
| LLM-based PDF generator | Was considered less suitable because of cost, another integration point, and limited control over the required design. |

## Decision and rationale

Build the report as HTML and CSS, then render it to PDF with Puppeteer. This gives the team direct control over the report layout without adding a separate PDF-generation service.

## Consequences

* Report styling can be changed in the HTML template.
* PDF output depends on Chromium and assets used by the template.
* Layout changes need visual checks against representative reports.
* The current template references a public CSS CDN, whose availability may affect rendering.

## Implementation evidence

The [report template](https://github.com/TQKNG/automation/blob/27045ec413f88cd2227ab08e18ec76db3e8e3d34/src/functions/shared/utils/reportTemplateService.js) builds the HTML. The [report service](https://github.com/TQKNG/automation/blob/27045ec413f88cd2227ab08e18ec76db3e8e3d34/src/functions/shared/utils/reportService.js) renders it as a PDF.

## Revisit when

Reconsider this approach if report design needs exceed the template's capabilities or Chromium packaging and resource use become unacceptable.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.