Download automation/scripts/html-to-pdf.js from EnergyVenom/patchwise-agent-studio: direct link, hf CLI and curl.
- Browser
- Download file 1.62 kB
-
https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/automation/scripts/html-to-pdf.js
- Command line
-
hf download hf://spaces/EnergyVenom/patchwise-agent-studio/automation/scripts/html-to-pdf.js
-
curl -L -o html-to-pdf.js https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/automation/scripts/html-to-pdf.js
1.62 kB
| // Co-worker report export: render a local HTML report to PDF with Playwright's Chromium (already installed). | |
| // Usage: node scripts/html-to-pdf.js <input.html> <output.pdf> [footer text]. Local files only; no network. | |
| // The page size and margins come from the report's own @page rule; the optional footer is printed on every page with | |
| // the page number ("<footer text> · Page 2 of 5"). | |
| const { chromium } = require('@playwright/test'); | |
| const esc = (s) => String(s).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c])); | |
| (async () => { | |
| const [inp, out, footer] = process.argv.slice(2); | |
| if (!inp || !out) { console.error('usage: html-to-pdf.js <input.html> <output.pdf> [footer text]'); process.exit(2); } | |
| const b = await chromium.launch(); | |
| try { | |
| const p = await b.newPage(); | |
| await p.goto('file:///' + inp.replace(/\\/g, '/')); | |
| await p.pdf({ | |
| path: out, | |
| format: 'A4', | |
| printBackground: true, | |
| preferCSSPageSize: true, | |
| displayHeaderFooter: !!footer, | |
| headerTemplate: '<span></span>', | |
| footerTemplate: footer | |
| ? `<div style="width:100%;padding:0 16mm;font:7.5pt -apple-system,'Segoe UI','Liberation Sans',Arial,sans-serif;color:#8e8e93;display:flex;justify-content:space-between">` | |
| + `<span>${esc(footer)}</span><span>Page <span class="pageNumber"></span> of <span class="totalPages"></span></span></div>` | |
| : '<span></span>', | |
| }); | |
| } finally { | |
| await b.close(); | |
| } | |
| })().catch((e) => { console.error(e); process.exit(1); }); | |