home / skills / aviz85 / claude-skills-library / html-to-pdf

This skill converts HTML to PDF with pixel-perfect rendering and Hebrew/RTL support, ensuring accurate layouts and font handling for web content.

npx playbooks add skill aviz85/claude-skills-library --skill html-to-pdf

Review the files below or copy the command above to add this skill to your agents.

Files (4)
skill.md
5.9 KB
No content available

Overview

This skill converts HTML and web pages to pixel-perfect PDFs using a headless Chrome renderer with strong Hebrew and RTL language support. It preserves CSS3/HTML5 fidelity, executes JavaScript, loads web fonts, and auto-detects or forces RTL direction for accurate Hebrew/Arabic output. It is optimized for single-page exports and fine-grained print control.

How this skill works

The converter launches Puppeteer (headless Chrome) to render the HTML exactly as a browser would, waits for network and font readiness, then prints to PDF using CSS @page rules and device scaling for crisp output. It supports loading custom fonts, background graphics, header/footer templates, and command-line options for format, margins, scale, orientation, and RTL handling. Automatic RTL detection or an explicit --rtl flag ensures correct direction and alignment for Hebrew and other RTL content.

When to use it

  • You need a faithful, pixel-perfect PDF of a web page or local HTML file.
  • Generating PDFs that include Hebrew, Arabic, or other RTL languages with correct direction and fonts.
  • Exporting dynamic pages that require JS execution and web font loading before printing.
  • Creating single-page documents like invoices, posters, or one-page reports.
  • Producing printable PDFs with precise margins, headers/footers, or background graphics.

Best practices

  • Keep backgrounds off html/body; apply them to a full-size container to avoid extra pages.
  • Set @page size and zero margins in CSS, and match html/body dimensions to the target page (e.g., 210mm x 297mm for A4).
  • Use overflow: hidden and box-sizing to prevent accidental overflow and extra pages.
  • Include lang and dir attributes (e.g., <html lang="he" dir="rtl">) and use UTF-8 for Hebrew content.
  • Load web fonts that support Hebrew (Noto Sans Hebrew, Heebo, Assistant) and allow extra wait time (--wait) for font loading if needed.

Example use cases

  • Convert a marketing landing page to a PDF poster with full-bleed background and custom margins.
  • Generate Hebrew invoices or letters with correct RTL layout and embedded web fonts using --rtl.
  • Export a dynamic report page that requires JS chart rendering to a single-page PDF.
  • Create landscape presentation slides as PDF with --landscape and custom scale for high-resolution output.
  • Batch-convert a set of local HTML documents to PDFs while preserving print CSS and headers/footers.

FAQ

How do I avoid extra blank pages in the PDF?

Put backgrounds on a container element rather than html/body, set explicit page dimensions and margins in CSS, and use overflow: hidden to prevent content overflow. You can also reduce scale (--scale) or margins if content still overflows.

My Hebrew text renders left-to-right. How can I fix that?

Add dir="rtl" to your html element, include direction: rtl; text-align: right; in CSS, or use the --rtl flag to force RTL rendering. Ensure you use a Hebrew-capable font and allow extra wait time for fonts to load.