Orpheus Systems Architecture

10. HTML template for the timesheet PDF

10. HTML template for the timesheet PDF

Date: 2026-10-22

Status

Accepted


Problem

The built-in timesheet layout (ADR 0004) is fixed in code. Organisations that use the web part want their own page: a logo, other header fields, different signature boxes, footnotes. Each such request is a code change and a release. The colour-coded grid and the totals must keep the exact look and numbers of the built-in PDF, and the solution still has no server component.


Decision

We will let a site owner supply the page as an HTML file stored on the SharePoint site, and render it client-side with html-to-pdfmake into the same pdfmake pipeline as ADR 0004.

Authoring guide: docs/timesheet-templates.md.

Template rendering into the pdfmake pipeline

flowchart TB
  P["Web part property<br/>Timesheet template<br/>(optional)"] --> Q{"Path set?"}
  Q -->|"site- or<br/>server-relative path"| F["Fetch the HTML file<br/>from the site<br/>on every generation,<br/>no cache"]
  Q -->|"empty"| BI["Built-in layout<br/>ADR 0004 doc definition,<br/>unchanged"]
  F --> PH["Fill placeholders<br/>contract, contractor,<br/>period, totals, labels,<br/>generatedOn, custom"]
  PH --> H2P["html-to-pdfmake<br/>HTML to pdfmake nodes"]
  H2P --> SW["Swap in generated<br/>blocks: grid, grid.days,<br/>totals, header, signatures"]
  GEN["Block builders<br/>same code as the<br/>built-in PDF"] --> SW
  GEN --> BI
  SW --> ATT["Append the Orpheus<br/>attribution line"]
  SW -.->|"broken template"| ERR["Error list shown<br/>nothing downloaded<br/>no fallback"]
  ATT --> PM["pdfmake<br/>in the browser"]
  BI --> PM
  PM --> DL["Download PDF"]

Alternatives considered

Option Summary Pros Cons
✅ html-to-pdfmake over a SharePoint-hosted template Convert the filled HTML to pdfmake nodes; swap in generated blocks Vector, searchable text; no server; reuses pdfmake and the existing builders CSS subset; Roboto only
html2canvas + jsPDF Render the HTML to a canvas and place the image on a page Any CSS works Raster output, blurry text, large files, no searchable text; rejected in ADR 0004 for the same reasons
Headless Chromium on a server Print HTML to PDF in a service Full CSS fidelity Needs Azure or similar hosting, auth and cost; breaks the no-server rule
HTML-rendered grid Let the template draw the grid itself from data Maximum freedom Every template re-implements the colour rules and totals; easy to get numbers wrong on a signed document

Consequences

Positive:

Negative / Trade-offs:

Risks: | Risk ID | Description | Impact (E/H/M/L) | Mitigation | |---------|-------------|------------------|------------| | R1 | html-to-pdfmake adds to the lazy PDF chunk | L | It loads only with pdfmake in the orpheus-timesheet-pdf chunk, never in the main bundle | | R2 | A template editor changes a signed document's look | M | Store the file where only site owners can edit; the guide says so | | R3 | The Vendor column ID clashes with an existing site column | L | The script checks all names and IDs first and stops before any change |