Adding High‑Resolution PNG Export to the Hotel IT Ops Dashboard with html‑to‑image
TL;DR: I integrated the html-to-image library into the dashboard to let users export any panel as a 300 dpi PNG for Google Slides. The change required a new vendor file, a version‑busting script tag, and a small UI hook in public/js/app.js.
The Problem
The dashboard is used daily by the IT ops team to present ticket trends in meetings. The existing “Download CSV” button covered data export, but the visual charts (Chart.js canvases and custom HTML tables) had to be screenshotted manually. Screenshots produced low‑resolution PNGs that looked blurry when pasted into Google Slides, breaking the visual consistency of our reports.
Error we saw when trying to upscale a screenshot:
Uncaught DOMException: Failed to execute 'toDataURL' on 'HTMLCanvasElement': The canvas has been tainted by cross‑origin data. The root cause was that the chart canvas was rendered with external fonts and images, and the browser blocked the toDataURL call, yielding a corrupted image.
What I Tried First
Canvas
toBlob+ Scaling – I attempted to grab the Chart.js canvas, draw it onto a larger off‑screen canvas, and calltoBlob. This worked for pure canvas charts but failed for mixed HTML tables because the dashboard mixes<canvas>and regular DOM elements.dom-to-image– The olderdom-to-imagelibrary claimed to handle full DOM trees. I added it via a CDN, but the minified file pulled in a polyfill that conflicted with our existingchart.umd.min.js, causing aReferenceError: Promise is not definedin older Safari versions used by some team members.
Both approaches either broke the UI or produced low‑quality PNGs, so I needed a more robust solution.
The Implementation
1. Add the library as a vendor asset
I decided to use html-to-image (MIT‑licensed) because it supports inline SVG, CSS, and external fonts when the useCORS flag is set. I copied the minified distribution into the repo:
public/vendor/html-to-image.min.js public/vendor/html-to-image-LICENSE.md The diff added the two files (see commit d0906046). The license file is required for compliance.
+!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).htmlToImage={}) 2. Bump the script version to force cache refresh
Our HTML references the main app bundle with a version query string. I added a new version (20261119h) to avoid stale caching after the vendor addition:
-<script src="/js/app.js?v=20261119g"></script> +<script src="/js/app.js?v=20261119h"></script> (Commit 6b4a83ab)
3. UI Hook – “Export PNG” button
In public/index.html I inserted a button next to the existing “Export CSV” control. The markup lives inside the panel header, so the button inherits the same styling:
<div class="panel-header"> <h2>Service Desk Overview</h2> <button id="export-png" class="btn btn-sm btn-primary"> 📷 Export PNG </button> </div> The diff added eight lines to the file (commit d0906046).
4. Export logic in public/js/app.js
The bulk of the work happened in app.js. I wrapped the export in a promise chain that:
- Finds the target panel (
#panel-sd). - Calls
htmlToImage.toBlobwithpixelRatio: 3(≈300 dpi on a 96 dpi screen). - Generates a temporary
<a>element to trigger a download.
// ── Exportar láminas como imagen (PNG) ─────────────────────────────────────── function exportPanelAsPng(panelId) { const node = document.querySelector(panelId); if (!node) return Promise.reject('Panel not found'); // html-to-image options – increase pixelRatio for high‑res output const opts = { backgroundColor: null, // preserve transparent backgrounds pixelRatio: 3, useCORS: true, // allow cross‑origin images/fonts }; return htmlToImage.toBlob(node, opts) .then(blob => { const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `${panelId.replace('#', '')}.png`; a.click(); URL.revokeObjectURL(url); }) .catch(err => { console.error('Export failed:', err); showSaveMsg('Export failed – check console', true); }); } // Bind button document.getElementById('export-png') .addEventListener('click', () => exportPanelAsPng('#panel-sd')); Key points:
-
pixelRatio: 3– multiplies the canvas size, giving us roughly 300 dpi output without manually scaling the DOM. -
useCORS: true– required because the dashboard loads the UHPCM logo from/public/assets/logos/UHPCM.png. The image is served from the same origin, but the flag prevents future cross‑origin issues if we ever switch to a CDN. - Error handling –
showSaveMsgis the existing toast helper; I reused it to surface failures.
The diff added ~60 lines to app.js (commit d0906046).
5. Adjusting the build/deploy pipeline
Because the dashboard is deployed on Vercel with a linked account identity (commit 6b4a83ab), I verified that the new vendor files are included in the Vercel build output. The vercel.json (unchanged) automatically copies everything under public/, so no extra configuration was needed.
6. Verify the result
After deploying, I opened the dashboard, clicked “Export PNG”, and inspected the downloaded file:
- Dimensions: original panel (800 × 600) → PNG (2400 × 1800).
- No blur when inserted into Google Slides at 16:9 slide size.
- Console shows no CORS errors.
Key Takeaway
When you need high‑resolution exports of mixed HTML/CSS/Canvas content, use html-to-image with an increased pixelRatio and useCORS flag. It handles SVG, external fonts, and images in a single pass, avoiding the pitfalls of canvas‑only approaches or older DOM‑to‑image libraries.
What's Next
- Batch Export – Add a “Export All Panels” button that loops over an array of panel selectors and zips the PNGs server‑side.
- Custom DPI Slider – Expose a UI control to let users choose the pixel ratio (1×, 2×, 3×).
- Automated Tests – Write Cypress tests that stub
htmlToImage.toBlobto ensure the export flow never regresses.
Roberto Luna Osorio – Full Stack Developer & Project Lead
Playa del Carmen, México
vibecoding #buildinpublic #javascript #nodejs #docker #vercel #html-to-image #frontend
Part of my Build in Public series — sharing the real process of building SaaS projects from Playa del Carmen, México.
Repo: zaerohell/hotel-it-ops-dashboard · 2026-11-19
#playadev #buildinpublic



