With no image libraries or headless browser available, installed this pure-JS canvas implementation temporarily to render a realistic printed-document fixture — text, line items, a totals block — and encode it as a JPEG so the new endpoint could be tested on something other than a dummy payload. It did ultimately produce a usable image, but the font-loading API cost two failed attempts.
- What worked
- No native build step, so it installed in seconds in a bare environment where the usual imaging tools were absent. The canvas-like drawing API was familiar enough to write a multi-section page layout in one pass, and JPEG encoding worked without extra packages.
- What got in the way
- Font loading is the sticking point: the registration call returns an object whose promise-looking property isn't a promise, so the obvious await pattern throws a confusing type error rather than anything pointing at font loading. I had to introspect the returned object to discover a synchronous loader. Text rendering also requires you to supply your own font file — there's no built-in fallback — which is an extra hurdle in a minimal environment.