html-to-pdf by aviz85/claude-skills-library
npx skills add https://github.com/aviz85/claude-skills-library --skill html-to-pdf首次使用? 如果上方显示
setup_complete: false,请先运行./SETUP.md,然后将setup_complete设置为true。
使用 Puppeteer(无头 Chrome)实现像素级精确的 HTML 转 PDF 转换。通过自动方向检测,为希伯来语、阿拉伯语和其他从右至左(RTL)语言提供出色的支持。
html 或 body 上的背景会导致额外页面! 请将背景放在容器元素上:
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
@page { size: A4; margin: 0; }
html, body {
width: 210mm;
height: 297mm;
margin: 0;
padding: 0;
overflow: hidden;
/* 此处不要设置背景! */
}
.container {
width: 100%;
height: 100%;
padding: 20mm;
box-sizing: border-box;
background: linear-gradient(...); /* 背景放在这里 */
}
导致额外页面的常见原因:
.container 上overflow: hidden提示:
--scale=0.75 --margin=0--landscape首次使用前,请安装依赖项:
cd ~/.claude/skills/html-to-pdf && npm install
node ~/.claude/skills/html-to-pdf/scripts/html-to-pdf.js input.html output.pdf
node ~/.claude/skills/html-to-pdf/scripts/html-to-pdf.js https://example.com page.pdf
node ~/.claude/skills/html-to-pdf/scripts/html-to-pdf.js hebrew.html hebrew.pdf --rtl
echo "<h1>שלום עולם</h1>" | node ~/.claude/skills/html-to-pdf/scripts/html-to-pdf.js - output.pdf --rtl
| 选项 | 描述 | 默认值 |
|---|---|---|
--format=<format> | 页面格式:A4, Letter, Legal, A3, A5 | A4 |
--landscape | 使用横向方向 | false |
--margin=<value> | 设置所有边距(例如:"20mm", "1in") | 20mm |
--margin-top=<value> | 上边距 | 20mm |
--margin-right=<value> | 右边距 | 20mm |
--margin-bottom=<value> | 下边距 | 20mm |
--margin-left=<value> | 左边距 | 20mm |
--scale=<number> | 缩放因子 0.1-2.0 | 1 |
--background | 打印背景图形 | true |
--no-background | 不打印背景 | - |
--header=<html> | 页眉 HTML 模板 | - |
--footer=<html> | 页脚 HTML 模板 | - |
--wait=<ms> | 字体/JS 的等待时间 | 1000 |
--rtl | 强制 RTL 方向 | 自动检测 |
node ~/.claude/skills/html-to-pdf/scripts/html-to-pdf.js report.html report.pdf
node ~/.claude/skills/html-to-pdf/scripts/html-to-pdf.js doc.html doc.pdf --format=Letter --margin=1in
node ~/.claude/skills/html-to-pdf/scripts/html-to-pdf.js invoice-he.html invoice.pdf --rtl
node ~/.claude/skills/html-to-pdf/scripts/html-to-pdf.js slides.html slides.pdf --landscape --format=A4
node ~/.claude/skills/html-to-pdf/scripts/html-to-pdf.js poster.html poster.pdf --margin=0
为了在您的 HTML 中获得最佳的希伯来语渲染效果:
<html lang="he" dir="rtl"><meta charset="UTF-8">direction: rtl; text-align: right;<!DOCTYPE html>
<html lang="he" dir="rtl">
<head>
<meta charset="UTF-8">
<link href="https://fonts.googleapis.com/css2?family=Heebo:wght@400;700&display=swap" rel="stylesheet">
<style>
@page { size: A4; margin: 0; }
html, body {
width: 210mm;
height: 297mm;
margin: 0;
padding: 0;
overflow: hidden;
}
.container {
width: 100%;
height: 100%;
padding: 20mm;
box-sizing: border-box;
font-family: 'Heebo', sans-serif;
direction: rtl;
text-align: right;
background: #f5f5f5; /* 背景在容器上,而不是 body */
}
</style>
</head>
<body>
<div class="container">
<h1>שלום עולם</h1>
<p>זהו מסמך בעברית</p>
</div>
</body>
</html>
--wait=2000 以增加字体加载时间@font-face 或 Google Fonts 加载--rtl 标志强制 RTL 方向dir="rtl"使用 CSS 分页属性:
.page-break { page-break-after: always; }
.no-break { page-break-inside: avoid; }
--background(默认为 true)--no-background关键 - Claude 必须在每次生成 PDF 后执行此操作:
这不是可选的。切勿在未经视觉验证的情况下交付 PDF。
| 问题 | 症状 | 修复方法 |
|---|---|---|
| 垂直溢出 | 页面底部有空白,内容在下一页 | 减小 --scale |
| 水平截断 | 文本在左/右边缘被截断 | 减小 --margin 并修复 HTML 宽度 |
| 两个问题都有 | 内容被截断且有多余页面 | 先修复 HTML CSS,然后调整缩放比例 |
尝试 1: 默认设置
node scripts/html-to-pdf.js input.html output.pdf
尝试 2: 如果垂直溢出 → 减小缩放比例
node scripts/html-to-pdf.js input.html output.pdf --scale=0.9
尝试 3: 如果水平截断 → 减小边距
node scripts/html-to-pdf.js input.html output.pdf --scale=0.9 --margin=10mm
尝试 4: 如果仍有问题 → 更小的缩放比例 + 边距
node scripts/html-to-pdf.js input.html output.pdf --scale=0.8 --margin=5mm
尝试 5: 如果仍然失败 → 修复 HTML CSS:
/* 添加到 HTML 以防止水平溢出 */
.container {
width: 100%;
max-width: 100%;
overflow-wrap: break-word;
word-wrap: break-word;
box-sizing: border-box;
}
5 次尝试后停止 - 使用适当的约束重新生成 HTML。
如果内容在边缘被截断,HTML 必须包含:
html, body {
width: 210mm; /* A4 宽度 */
margin: 0;
padding: 0;
overflow: hidden;
}
.container {
width: 100%;
max-width: 100%;
padding: 15mm;
box-sizing: border-box;
overflow-wrap: break-word;
}
每次生成 PDF 后,请验证:
如果任何检查失败 → 调整并重新生成(最多 5 次)。
networkidle0 以确保所有资源加载完毕document.fonts.ready@page CSS 规则进行打印样式设置每周安装次数
446
代码仓库
GitHub 星标数
18
首次出现
Jan 20, 2026
安全审计
安装于
opencode375
gemini-cli357
codex332
cursor328
github-copilot299
claude-code297
First time? If
setup_complete: falseabove, run./SETUP.mdfirst, then setsetup_complete: true.
Pixel-perfect HTML to PDF conversion using Puppeteer (Chrome headless). Provides excellent support for Hebrew, Arabic, and other RTL languages with automatic direction detection.
Backgrounds onhtml or body cause extra pages! Put backgrounds on a container element instead:
@page { size: A4; margin: 0; }
html, body {
width: 210mm;
height: 297mm;
margin: 0;
padding: 0;
overflow: hidden;
/* NO background here! */
}
.container {
width: 100%;
height: 100%;
padding: 20mm;
box-sizing: border-box;
background: linear-gradient(...); /* Background goes HERE */
}
Common causes of extra pages:
.container insteadoverflow: hiddenTips:
--scale=0.75 --margin=0 if content still overflows--landscapeBefore first use, install dependencies:
cd ~/.claude/skills/html-to-pdf && npm install
node ~/.claude/skills/html-to-pdf/scripts/html-to-pdf.js input.html output.pdf
node ~/.claude/skills/html-to-pdf/scripts/html-to-pdf.js https://example.com page.pdf
node ~/.claude/skills/html-to-pdf/scripts/html-to-pdf.js hebrew.html hebrew.pdf --rtl
echo "<h1>שלום עולם</h1>" | node ~/.claude/skills/html-to-pdf/scripts/html-to-pdf.js - output.pdf --rtl
| Option | Description | Default |
|---|---|---|
--format=<format> | Page format: A4, Letter, Legal, A3, A5 | A4 |
--landscape | Use landscape orientation | false |
--margin=<value> | Set all margins (e.g., "20mm", "1in") | 20mm |
--margin-top=<value> | Top margin | 20mm |
--margin-right=<value> | Right margin |
node ~/.claude/skills/html-to-pdf/scripts/html-to-pdf.js report.html report.pdf
node ~/.claude/skills/html-to-pdf/scripts/html-to-pdf.js doc.html doc.pdf --format=Letter --margin=1in
node ~/.claude/skills/html-to-pdf/scripts/html-to-pdf.js invoice-he.html invoice.pdf --rtl
node ~/.claude/skills/html-to-pdf/scripts/html-to-pdf.js slides.html slides.pdf --landscape --format=A4
node ~/.claude/skills/html-to-pdf/scripts/html-to-pdf.js poster.html poster.pdf --margin=0
For best Hebrew rendering in your HTML:
<html lang="he" dir="rtl"><meta charset="UTF-8">direction: rtl; text-align: right; to body<!DOCTYPE html>
<html lang="he" dir="rtl">
<head>
<meta charset="UTF-8">
<link href="https://fonts.googleapis.com/css2?family=Heebo:wght@400;700&display=swap" rel="stylesheet">
<style>
@page { size: A4; margin: 0; }
html, body {
width: 210mm;
height: 297mm;
margin: 0;
padding: 0;
overflow: hidden;
}
.container {
width: 100%;
height: 100%;
padding: 20mm;
box-sizing: border-box;
font-family: 'Heebo', sans-serif;
direction: rtl;
text-align: right;
background: #f5f5f5; /* Background on container, NOT body */
}
</style>
</head>
<body>
<div class="container">
<h1>שלום עולם</h1>
<p>זהו מסמך בעברית</p>
</div>
</body>
</html>
--wait=2000 for more font loading time@font-face or Google Fonts--rtl flag to force RTL directiondir="rtl" to your HTML elementUse CSS page-break properties:
.page-break { page-break-after: always; }
.no-break { page-break-inside: avoid; }
--background is set (default is true)--no-background only if you want to exclude backgroundsCRITICAL - Claude MUST do this after EVERY PDF generation:
This is NOT optional. Never deliver a PDF without visual verification.
| Problem | Symptom | Fix |
|---|---|---|
| Vertical overflow | Empty space at page bottom, content on next page | Reduce --scale |
| Horizontal cut-off | Text cut at left/right edges | Reduce --margin AND fix HTML width |
| Both issues | Content cut AND extra pages | Fix HTML CSS first, then adjust scale |
Attempt 1: Default settings
node scripts/html-to-pdf.js input.html output.pdf
Attempt 2: If vertical overflow → reduce scale
node scripts/html-to-pdf.js input.html output.pdf --scale=0.9
Attempt 3: If horizontal cut-off → reduce margins
node scripts/html-to-pdf.js input.html output.pdf --scale=0.9 --margin=10mm
Attempt 4: If still issues → smaller scale + margins
node scripts/html-to-pdf.js input.html output.pdf --scale=0.8 --margin=5mm
Attempt 5: If still failing → FIX THE HTML CSS:
/* Add to HTML to prevent horizontal overflow */
.container {
width: 100%;
max-width: 100%;
overflow-wrap: break-word;
word-wrap: break-word;
box-sizing: border-box;
}
STOP after 5 attempts - regenerate HTML with proper constraints.
If content is cut at sides, the HTML MUST have:
html, body {
width: 210mm; /* A4 width */
margin: 0;
padding: 0;
overflow: hidden;
}
.container {
width: 100%;
max-width: 100%;
padding: 15mm;
box-sizing: border-box;
overflow-wrap: break-word;
}
After EVERY PDF generation, verify:
If ANY check fails → adjust and regenerate (max 5 times).
networkidle0 to ensure all resources loaddocument.fonts.ready@page CSS rules for print stylingWeekly Installs
446
Repository
GitHub Stars
18
First Seen
Jan 20, 2026
Security Audits
Gen Agent Trust HubWarnSocketPassSnykWarn
Installed on
opencode375
gemini-cli357
codex332
cursor328
github-copilot299
claude-code297
agent-browser 浏览器自动化工具 - Vercel Labs 命令行网页操作与测试
136,300 周安装
OpenAPI 转 TypeScript 工具 - 自动生成 API 接口与类型守卫
563 周安装
数据库模式设计器 - 内置最佳实践,自动生成生产级SQL/NoSQL数据库架构
564 周安装
Rust Unsafe代码检查器 - 安全使用Unsafe Rust的完整指南与最佳实践
564 周安装
.NET并发编程模式指南:async/await、Channels、Akka.NET选择决策树
565 周安装
韩语语法检查器 - 基于国立国语院标准的拼写、空格、语法、标点错误检测与纠正
565 周安装
技能安全扫描器 - 检测Claude技能安全漏洞,防范提示注入与恶意代码
565 周安装
| 20mm |
--margin-bottom=<value> | Bottom margin | 20mm |
--margin-left=<value> | Left margin | 20mm |
--scale=<number> | Scale factor 0.1-2.0 | 1 |
--background | Print background graphics | true |
--no-background | Don't print backgrounds | - |
--header=<html> | Header HTML template | - |
--footer=<html> | Footer HTML template | - |
--wait=<ms> | Wait time for fonts/JS | 1000 |
--rtl | Force RTL direction | auto-detect |