html-pdf-export
Skill0 starsChanged 4 months agoMITView on GitHub
Build pixel-perfect PDF-exportable HTML documents. Use when creating proposals, reports, pitch decks, or any HTML document that needs to export as a beautiful multi-page PDF. The pattern: beautiful web design for the screen, separate hidden print-only section for print, window.print() to export. No libraries, no canvas capture, no page break guessing. Triggers on: PDF export, print-ready HTML, proposal document, printable report, export to PDF.
In this repository37 other files it gives its agents.
- .agents/skills/vercel-composition-patterns/AGENTS.mdAGENTS.md
- vercel-composition-patterns/AGENTS.mdAGENTS.md
- senior-frontendSkill
- vercel-composition-patternsSkill
- bento-designSkill
- fanned-cardsSkill
- flip-cardSkill
- floating-quotesSkill
- githubSkill
- glassmorphism-uiSkill
- gmail-proxySkill
- googleSkill
- hippocampusSkill
- iframe-previewSkill
- infinite-canvasSkill
- matrix-textSkill
- nextjs-apiSkill
- nextjs-expertSkill
- pinterestSkill
- railway-deploySkill
- remotion-videoSkill
- scramble-textSkill
- scroll-video-heroSkill
- senior-frontendSkill
- SEOSkill
- ship-websiteSkill
- sound-engineSkill
- stripe-best-practicesSkill
- tilt-cardSkill
- tube-summarySkill
- upload-postSkill
- vercel-composition-patternsSkill
- vercel-deploySkill
- vercel-react-best-practicesSkill
- vertical-fanned-cardsSkill
- video-contentSkill
- war-roomSkill
The file
Files
HTML PDF Export
The pattern: build two versions of the document in one HTML file — a rich web version for the screen, and a separate hidden print-only section purpose-built for A4. window.print() does the rest.
Why not html2canvas/html2pdf? Canvas capture scrambles complex CSS layouts, mishandles fonts, and can't reliably detect page breaks. Browser print is far more reliable when the print HTML is purpose-built for it.
File structure
<style>
/* Screen styles — full design, no restrictions */
...
/* Print: hide web, show print section */
#print-report { display: none; }
@media print {
@page { size: A4; margin: 0; }
.web-page, .export-btn { display: none !important; }
#print-report { display: block !important; }
/* Page container — one per PDF page */
.pp {
width: 210mm;
min-height: 297mm;
page-break-after: always;
-webkit-print-color-adjust: exact;
print-color-adjust: exact;
color-adjust: exact;
font-family: 'Barlow', sans-serif; /* or whatever web font is loaded */
}
.pp:last-child { page-break-after: auto; }
/* All colored elements need print-color-adjust */
.pp-dark-header, .pp-card-header, .pp-footer {
-webkit-print-color-adjust: exact;
print-color-adjust: exact;
}
}
</style>
<!-- Web design (hidden in print) -->
<div class="web-page"> ... </div>
<!-- Print-only report (hidden on screen) -->
<div id="print-report">
<div class="pp"> <!-- Page 1 --> </div>
<div class="pp"> <!-- Page 2 --> </div>
<div class="pp"> <!-- Page 3 --> </div>
</div>Critical rules
- Every
.ppdiv = one A4 page. Design content to fit. Don't rely on the browser to split content mid-card. print-color-adjust: exacton EVERY element with a background color, not just the page container. Dark headers, colored cards, tinted boxes — all need it, or Chrome strips the color.- Font sizes in px, not mm/pt. The browser handles A4 scaling. Use ~9-11px for body, ~12-14px for headings at print scale.
- Padding in mm for page-level spacing (e.g.,
padding: 12mm 14mm), px for component internals. - No border-radius issues — border-radius works fine in Chrome print. Box shadows do not render — remove them from print styles.
- Google Fonts work — they're already loaded in the browser, so they render correctly in print. No fallback needed.
Export button
<button onclick="window.print()">Export PDF</button>That's it. No libraries. In Chrome, "Save as PDF" → destination = "Save as PDF", margins = None.
Sizing guide (A4 = 210mm × 297mm)
With padding: 12mm 14mm:
- Content width: 182mm
- Content height: 273mm
Typical 3-page split for a proposal:
- Page 1: Cover/intro (header + stats + 1 section)
- Page 2: Main content (2-3 option cards)
- Page 3: Supporting content + footer
Asset
See assets/template.html for a minimal two-page starter with dark header, stats bar, card, and footer — all print-ready.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

