@formepdf/html

中文文档
0.31.0发布于 2026/11/06MITTypeScriptES Module零依赖近 30 天下载 3.4万

HTML + print-CSS to PDF on the Forme engine — pagination, running headers, page counters. No headless browser.

原始使用文档

@formepdf/html

HTML + print-CSS to PDF on the Forme engine. No headless browser, no Chromium cold start — a Rust layout engine compiled to WASM, running wherever Node runs.

npx @formepdf/html invoice.html
const { renderHtml } = require('@formepdf/html');

const { pdf, warnings } = renderHtml(html, { pageSize: 'Letter' });
fs.writeFileSync('invoice.pdf', pdf);
warnings.forEach((w) => console.warn(w)); // everything outside the subset, named

What works

The paged-media CSS browsers took two decades to ship — and the parts they still haven't:

  • @page: size (named or dimensions), margins, :first variants
  • Margin boxes (@top-center, @bottom-right, ...): running headers/footers in the page margin, with content() strings and counter(page) / counter(pages)
  • Break control: break-before/after/inside plus the legacy page-break-* spellings every wkhtmltopdf-era template still carries
  • orphans / widows, <thead> repetition on every page
  • Stylesheets with a documented selector subset, the full cascade with !important, flexbox, a CSS Grid subset, tables with colspan/rowspan, lists, images
  • Floats as column rows — float: left/right + clear lay consecutive floated siblings out as a row (the Bootstrap col-* and left/right header-pair shape real templates use); only true text-wrapping alongside a float is out, and it warns

Measured against 15 real production templates from GitHub (Bootstrap 2/3 grids, mPDF/wkhtmltopdf-era tables, email HTML, modern CSS grid): 14 of 15 render correctly, the one degraded case is legible with its cause named in warnings, zero render broken (as of 0.20.0).

The complete property-by-property subset table lives in the repository README — everything outside it lands in warnings, never silently dropped.

CLI

forme-html <input.html> [-o out.pdf] [--css print.css]
           [--page-size Letter] [--margin 36] [-q]

CLI/API options override the document's @page rule, the way a print dialog overrides a stylesheet.

版本与发布记录

@formepdf/html 共发布 19 个版本,首次发布于 2026/08/29;过去 12 个月发布了 19 个版本。

版本发布日期距今
0.31.0latest2026/11/0610 天前
0.30.02026/11/0411 天前
0.29.02026/10/2324 天前
0.28.02026/10/071 个月前
0.27.02026/10/031 个月前
0.26.02026/10/011 个月前

关于 @formepdf/html 的常见问题

@formepdf/html 是什么?

HTML + print-CSS to PDF on the Forme engine — pagination, running headers, page counters. No headless browser.

如何安装 @formepdf/html?

在项目目录运行 npm install @formepdf/html,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 forme-html,可以用 npx forme-html 直接运行。

@formepdf/html 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@formepdf/html 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@formepdf/html 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@formepdf/html 可以商用吗?

@formepdf/html 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@formepdf/html 的下载量有多少?

根据 npm 官方下载统计,@formepdf/html 在 2026/10/16 – 2026/11/14 这 30 天内被下载 34,294 次,日均约 1,143 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@formepdf/html 还在维护吗?

最新版本 0.31.0 发布于 2026/11/06(10 天前);至今共发布 19 个版本,其中过去 12 个月发布了 19 个;首次发布于 2026/08/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。