yugasun/skills · Archived

html-to-pdf

Export HTML files to PDF using Playwright with mobile emulation and custom viewport settings. Use this skill when the user asks to convert HTML to PDF, export presentations to PDF, or generate PDF documents from web pages.

First seen Feb 28, 2026

Installation

$ npx skills add yugasun/skills --skill html-to-pdf

Stronger alternatives

This repository is archived — consider an actively maintained alternative.

Similar popular skills

Related neighbors and high-traction skills in the same topics — useful to compare before installing.

Also in this package

Other skills from yugasun/skills.

npx skills add yugasun/skills

Browse all from yugasun/skills

More details

Agent compatibility

Declared targets from SKILL.md / docs. Unmarked agents are not listed — the skill may still install via the CLI.

Claude Code Not declared
Cursor Not declared
Codex Not declared
GitHub Copilot Not declared
Windsurf Not declared
Gemini CLI Not declared
Cline Not declared
OpenCode Not declared

Repository health

Stars 1
License LICENSE
Default branch main
Open issues 0
Status Archived

Package contents

Files included with this skill beyond the listing page.

  • skill md SKILL.md 2,848 B
  • docs SUMMARY.md 241 B

History

  1. First seen on skills.sh
  2. First recorded snapshot · 2 installs

SKILL.md

HTML to PDF Export

Export HTML files (local or URLs) to PDF using Playwright with configurable viewport and mobile emulation.

Quick Start

Use the provided script to export HTML to PDF:

uv run {baseDir}/scripts/export_to_pdf.py input.html output.pdf

Export urls:

uv run {baseDir}/scripts/export_to_pdf.py https://example.com output.pdf

Key Features

  • Mobile Emulation: 768px viewport for mobile-optimized rendering
  • Background Printing: Preserves colors and backgrounds
  • Dynamic Content: Waits for JavaScript execution (ECharts, animations, etc.)
  • Full Page Capture: Auto-detects page height for complete output
  • Debug Mode: Visual inspection before PDF generation

Technical Details

Viewport Configuration

  • Width: 768px (matches CSS @media (max-width: 768px) breakpoint)
  • Height: 1024px initial, expands to full content
  • Device Scale: 2x for retina displays
  • Mobile Mode: Enabled to trigger mobile-specific behaviors

Rendering Pipeline

  1. Load: Opens URL in Chromium browser with mobile viewport
  2. Wait: Network idle + 10s buffer for JS execution
  3. Measure: Calculates full page height via scrollHeight
  4. Export: Generates PDF with exact dimensions
  5. Cleanup: Closes browser and context

Wait Times

Default wait: 10 seconds after network idle

Adjust for heavy JS/animations:

# In export_to_pdf.py, modify:
page.wait_for_timeout(15000)  # 15 seconds

Dependencies

Install Playwright:

pip install playwright
playwright install chromium

Common Use Cases

  1. Slide Decks: Export presentation HTML with animations and charts
  2. Reports: Convert dynamic dashboards to static PDFs
  3. Documentation: Generate PDF versions of web documentation
  4. Newsletters: Archive HTML emails as PDFs

Troubleshooting

Missing Backgrounds

Already handled by injecting:

body {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
}

Content Cut Off

The script auto-detects page height. If issues persist:

  • Check if content is position: fixed/absolute
  • Verify viewport width triggers correct CSS breakpoints
  • Increase wait timeout for slow-loading content

Charts Not Rendering

Increase wait time in script:

page.wait_for_timeout(15000)  # or more

Script Reference

See scripts/exporttopdf.py for the complete implementation. The script is self-contained and can be used directly from the command line or imported as a module.