@0-ai/slide-gen

中文文档
0.1.2发布于 2026/03/28MITTypeScriptES Module构建来源已验证近 30 天下载 3607

Convert HTML slide decks to PPTX, PDF, and PNG

原始使用文档
文档目录15 节
  1. How it works
  2. Requirements
  3. Install
  4. CLI usage
  5. Options
  6. API usage
  7. File-based pipeline
  8. Buffer-based pipeline
  9. Low-level API
  10. HTML slide format
  11. Supported CSS
  12. Data attributes
  13. Not supported (silently ignored)
  14. Fonts
  15. License

slide-gen

Convert HTML slide decks to PPTX, PDF, and PNG. Design your slides with HTML + CSS, then export to native PowerPoint format with high-fidelity conversion.

How it works

slide-gen renders your HTML in a headless Chromium browser (via Playwright), extracts every visible element from the DOM — shapes, text runs, images, gradients — and reconstructs them as native OOXML objects inside a .pptx file. The result is a real PowerPoint file with editable text, not a rasterized image.

Requirements

  • Bun >= 1.0
  • Playwright Chromium (bunx playwright install chromium)
  • Optional: LibreOffice + Ghostscript (only for --render PPTX verification)

Install

bun add @0-ai/slide-gen

CLI usage

bunx slide-gen slides.html -o ./output

This generates presentation.pptx, presentation.pdf, and slide-*.png files in the output directory.

Options

-o, --output-dir <dir>   Output directory (default: ./output)
--no-pdf                 Skip PDF generation
--no-pptx                Skip PPTX generation
--no-png                 Skip PNG screenshots
--render                 Render PPTX back to PNG via LibreOffice (for verification)
--skip-fonts             Use previously cached fonts
--fonts-dir <dir>        Custom fonts cache directory

API usage

File-based pipeline

Reads HTML from disk, writes outputs to a directory:

import { convertHtmlToSlides } from "@0-ai/slide-gen";

const result = await convertHtmlToSlides("slides.html", {
  outputDir: "./output",
  onProgress: console.log,
});

console.log(result.pptxPath);  // ./output/presentation.pptx
console.log(result.pdfPath);   // ./output/presentation.pdf
console.log(result.pngPaths);  // ["./output/slide-1.png", ...]

Buffer-based pipeline

Accepts HTML as a string, returns everything as in-memory buffers — no output directory needed:

import { convertHtmlBuffers } from "@0-ai/slide-gen";

const result = await convertHtmlBuffers({
  html: "<html>...</html>",
  noPdf: true,   // skip PDF
  noPng: true,   // skip PNGs
});

// result.pptxBuffer — Buffer containing the .pptx file
// result.pngBuffers — Buffer[] of slide screenshots
// result.slideData  — extracted slide structure

Low-level API

Use individual pipeline stages directly:

import {
  launchBrowser,
  loadHtmlContent,
  extractSlideData,
  prepareFontsFromSlideData,
  buildPptx,
  generatePdfBuffer,
  generateSlidePngBuffers,
  closeBrowser,
} from "@0-ai/slide-gen";

HTML slide format

Each slide is a <div class="slide"> element sized at 1920x1080px:

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=1920, initial-scale=1" />
  <style>
    @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap');

    *, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

    body { background: #000; }

    .slide {
      position: relative;
      width: 1920px;
      height: 1080px;
      overflow: hidden;
      font-family: 'Inter', sans-serif;
      color: #fff;
      background: #0a0a0a;
    }
    .slide + .slide { page-break-before: always; }
  </style>
</head>
<body>
  <div class="slide">
    <h1 style="padding: 80px; font-size: 64px;">Hello, World</h1>
  </div>
  <div class="slide">
    <h1 style="padding: 80px; font-size: 64px;">Slide Two</h1>
  </div>
</body>
</html>

Supported CSS

FeatureNotes
Solid backgroundsbackground-color on any element
Linear & radial gradientslinear-gradient(), radial-gradient()
Flexbox & Grid layoutsPositions captured via getBoundingClientRect()
Google FontsAll weights (100-900) — auto-downloaded and embedded
BordersPer-side colors and widths (>=1px)
border-radiusUniform value (not per-corner)
OpacityAccumulated from ancestor chain
CSS variablesResolved by the browser before extraction
transform: rotate()Only rotation — no scale/skew/translate
::before / ::afterPosition, size, background only (no text)
Font stylingsize, weight, style, family, color, letter-spacing, line-height
Text formattingtext-transform, text-align
<img>, inline SVGRasterized and embedded as PNG
background-image: url()Single image backgrounds
writing-modevertical-rl/vertical-lr

Data attributes

Control conversion behavior with these attributes:

AttributeValuesPurpose
data-sg-wrap"true" / "false"Explicit text wrapping control
data-sg-groupany stringGroup text runs into a single PPTX text box

Not supported (silently ignored)

Shadows, filters, backdrop-filter, clip-path, text-decoration, transforms other than rotate(), conic gradients, multiple background layers, per-corner border-radius, positioned layout offsets.

Fonts

Google Fonts are automatically downloaded, cached locally (in .slide-gen-fonts/), and embedded into the PPTX file. System fonts work but only get binary bold — no weight variants.

Use --skip-fonts on subsequent runs to reuse the cached fonts.

License

MIT

版本与发布记录

@0-ai/slide-gen 共发布 3 个版本,首次发布于 2026/03/27;过去 12 个月发布了 3 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.1.2latest2026/03/287 个月前
0.1.12026/03/287 个月前
0.1.02026/03/277 个月前

关于 @0-ai/slide-gen 的常见问题

@0-ai/slide-gen 是什么?

Convert HTML slide decks to PPTX, PDF, and PNG

如何安装 @0-ai/slide-gen?

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

@0-ai/slide-gen 支持 TypeScript 吗?

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

@0-ai/slide-gen 支持 ESM 还是 CommonJS?

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

@0-ai/slide-gen 可以商用吗?

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

@0-ai/slide-gen 的下载量有多少?

根据 npm 官方下载统计,@0-ai/slide-gen 在 2026/10/04 – 2026/11/02 这 30 天内被下载 3,607 次,日均约 120 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@0-ai/slide-gen 还在维护吗?

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