Html to pdf

From jsath/claude-skills · View interactive version

Html to pdf is an AI agent skill from the GitHub repository jsath/claude-skills. Builds polished PDF documents (one-pagers, reports, guides, proposals, briefs) as HTML and CSS with exact page layout, renders them with headless Chromium through Playwright, then checks every page as an image before handing the file over. Fixed page sizes, controlled page breaks, no split tables, n

How to use this skill

Skill file

HTML to PDF

Most converters give you a PDF but not control: a half-empty last page, a lone heading at the bottom, a table cut in half. This skill writes the document as HTML and CSS, prints it with headless Chromium, and looks at every page before calling it done.

What it does

  1. Turns content (notes, a draft, data, a brief) into a single self-contained HTML file laid out page by page.
  2. Renders it to PDF with headless Chromium. No window ever opens.
  3. Exports each page as a PNG, checks it by eye and by script, fixes problems and renders again.
  4. Hands over the PDF with its page count, size and the QA it passed.

What you need

```

pip install playwright pypdf pypdfium2

python -m playwright install chromium

```

pypdfium2 is only for PNG export. If it is missing, the script falls back to pdftoppm from poppler.

Steps

  1. Plan the pages. Before writing HTML, write a one-line outline per page: what goes on page 1, page 2, and so on. A one-pager is one page. A report is usually a cover plus 2 to 6 pages. Decide the page count now, not after rendering.
  2. Copy the template. Start from templates/document.html. It has a cover page, a content page, a key-number grid, two columns, a table, a callout and a footer, all in neutral styling with [placeholders]. Swap the colour and font tokens in :root if the reader has a brand.
  3. Fill one .page block per planned page. Real content, not lorem ipsum. Lead with the point.
  4. Render:

```

python scripts/render_pdf.py report.html out/report.pdf --png-dir qa/ --expect-pages 3

```

It prints the page count, file size and PNG paths, and warns about overflowing content, fonts that did not load, broken images, and a mismatch between .page boxes and PDF pages. Add --strict to make any warning a failure.

  1. Look at every PNG against the QA list below. The script catches overflow; only your eyes catch ugly.
  2. Fix and render again. Repeat steps 4 and 5 until every page passes. Old PNGs are cleared on each run so you never review a stale render.

Layout rules

Two ways to lay out pages. Pick one per document.

Always:

QA

Run the script, then check each page image for:

After any fix, even a one-line CSS change, re-render the PDF and regenerate every PNG before saying it passed. Screenshots from before a fix prove nothing.

Output

Honest limits

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.