← 返回
未分类 中文

html-to-pdf

Convert an HTML file to a PDF using headless Chrome (Puppeteer) — the same approach atypica uses for its AI-generated research reports. Use this skill whenev...
Convert an HTML file to a PDF using headless Chrome (Puppeteer) — the same approach atypica uses for its AI-generated research reports. Use this skill whenev...
owenrao owenrao 来源
未分类 clawhub v1.0.0 1 版本 100000 Key: 无需
★ 0
Stars
📥 316
下载
💾 1
安装
1
版本
#latest

概述

Overview

This skill converts an HTML file to PDF using Puppeteer (headless Chromium), exactly

how atypica exports its AI research reports. Two modes are supported:

ModeWhen to use
-------------------
Single-page (default)Design/report pages meant to look like one tall poster — no page breaks. Full-width at 1440 px.
PaginatedDocuments meant to be printed or read page-by-page (A4, Letter, etc.).

Quickstart (3 steps)

# 1. Copy the bundled scripts to a working directory
cp <skill-dir>/scripts/html-to-pdf.js ./
cp <skill-dir>/scripts/package.json ./

# 2. Install the only dependency (downloads Chromium automatically, ~170 MB, one-time)
npm install

# 3. Run
node html-to-pdf.js report.html report.pdf

is the directory that contains this SKILL.md file.

> Note: npm install puppeteer (~170 MB) downloads a pinned Chromium binary.

> This is the only install step — no system Chrome, no wkhtmltopdf, no separate server needed.

> If the environment already has Puppeteer installed, skip step 2.


Command reference

node html-to-pdf.js <input.html> <output.pdf> [options]

Options:
  --paginated         A4-paginated mode (respects @media print, page-breaks)
  --format <fmt>      Page format: A4 (default), A3, Letter, Legal
  --width <px>        Viewport width for single-page mode (default: 1440)
  --wait <ms>         Extra milliseconds to wait after page load (for JS-rendered content)
  --header-footer     Add page-number footer in paginated mode

Examples

# Single-page full-height (atypica report style)
node html-to-pdf.js report.html report.pdf

# A4 paginated document
node html-to-pdf.js document.html document.pdf --paginated

# A4 with page numbers
node html-to-pdf.js document.html document.pdf --paginated --header-footer

# Narrower single-page layout
node html-to-pdf.js report.html report.pdf --width 1280

# Wait 2 s for JavaScript-rendered charts
node html-to-pdf.js dashboard.html dashboard.pdf --wait 2000

How it works (mirrors atypica's browser service)

  1. Launches headless Chromium via Puppeteer with sandbox disabled and CJK font hints enabled.
  2. Loads the HTML from a file:// URL so relative assets (images, local CSS) resolve correctly.
  3. Injects system-font CSS to ensure Chinese/Japanese/Korean characters render on any OS.
  4. Single-page mode: measures document.body.scrollHeight, sets viewport to that height, and generates a single-page PDF at that exact size — no clipping, no page breaks.
  5. Paginated mode: injects @media print CSS for clean page-breaks, then generates a standard-format paginated PDF.
  6. Writes the PDF buffer to the output path.

Handling common issues

ProblemFix
--------------
Chromium not found after npm install puppeteerRun npx puppeteer browsers install chrome
Missing system fonts / boxes instead of CJK charsInject works for most cases; for guaranteed rendering install fonts-noto-cjk (Linux) or ensure macOS system fonts are accessible
JavaScript-rendered content missingAdd --wait 2000 (or more) to let JS execute after load
Images not loadingMake sure image src paths are relative to the HTML file location
PDF cut off at bottomThe script auto-measures height; if content loads lazily add --wait
--no-sandbox error in strict containerPuppeteer requires --no-sandbox in Docker/CI; this flag is already set

Dependency notes

  • Node.js ≥ 18 required (≥ 20 recommended)
  • puppeteer is the only npm dependency — it self-contains Chromium
  • No global Chrome installation needed
  • Works on macOS, Linux, and Windows (WSL)
  • In CI/Docker, add --disable-dev-shm-usage (already included in the script)

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-05-07 11:54 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

business-ops

plan-as-consultant

owenrao
按照专业顾问的方式规划商业研究项目——选择合适的分析框架(JTBD、KANO、STP、GE‑McKinsey 等),设计...
★ 0 📥 425
office-efficiency

Gog

steipete
Google Workspace 命令行工具,支持 Gmail、日历、云端硬盘、通讯录、表格和文档。
★ 925 📥 186,548
office-efficiency

Excel / XLSX

ivangdavila
创建、检查和编辑 Microsoft Excel 工作簿及 XLSX 文件,支持可靠的公式、日期、类型、格式、重算及模板保留功能。
★ 379 📥 143,780