@diplodoc/pdf-generator

中文文档
2.0.0发布于 2026/11/06MITCommonJS构建来源已验证近 30 天下载 3358

Package to turn Diplodoc projects into PDFs

原始使用文档
文档目录8 节
  1. Installation
  2. Usage
  3. Step 1: Generate Single Page Files
  4. Step 2: Convert Single Page Files to PDFs
  5. Passed parameters
  6. Development
  7. Prerequisites
  8. Run test

pdf-generator

Package to turn Diplodoc projects into PDFs.

Installation

npm i -g @diplodoc/pdf-generator

Usage

Step 1: Generate Single Page Files

Run @diplodoc/cli command. This will create an output folder with a single page file for each Table of Contents (ToC) file.

npx -- @diplodoc/cli@latest -i ./docs -o ./docs-output --pdf

Step 2: Convert Single Page Files to PDFs

Run the @diplodoc/pdf-generator command. This will create PDF files right next to the single page ones.

npx -- @diplodoc/pdf-generator@latest -i ./docs-output

The tool also provides users with flexible customization of headers and footers in the form of HTML format files, the paths to which can be passed through the corresponding options --custom-header and --custom-footer.

By default, the header is not set, but the page numbering in the lower right corner is set in the footer, as shown in the example below.

npx -- @diplodoc/pdf-generator@latest -i ./docs-output

Also below is an example of a command with custom header (example-custom-header.html) and custom footer (example-custom-footer.html).
Even if you specify a custom footer, the numbering still remains in the lower right corner.

npx -- @diplodoc/pdf-generator@latest -i ./docs-output --custom-header ./example-custom-header.html --custom-footer ./example-custom-footer.html

Passed parameters

OptionTypeNecessaryDefault valueDescription
custom-headerstring (filepath)No""Path to HTML file with custom header content for generated PDF pages.
custom-footerstring (filepath)No<div style="position: relative;width: 100%;height: 0;"><div style="position: absolute;right: 20px;bottom: 0;font-size: 10px;z-index: 0;padding: 0 5px;background: white;"><span class="pageNumber"></span></div></div>Path to HTML file with custom footer content for generated PDF pages.

Examples of generated pdf pages with custom headers and footers are available on screenshots tests/image_snapshots /custom-headers-test-ts-integration-works-on-page-*

Development

Prerequisites

  • node >= 18.x
  • graphicsmagick
  • ghostscript

Don't have graphicsmagick and ghostscript yet?

Follow this guide to install the required dependencies.

Run test

npm run test

版本与发布记录

@diplodoc/pdf-generator 共发布 37 个版本,首次发布于 2024/06/21;过去 12 个月发布了 22 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.0.0latest2026/11/066 天前
1.5.92026/07/173 个月前
1.5.82026/07/024 个月前
1.5.72026/06/264 个月前
1.5.62026/06/244 个月前
1.5.52026/06/234 个月前

关于 @diplodoc/pdf-generator 的常见问题

@diplodoc/pdf-generator 是什么?

Package to turn Diplodoc projects into PDFs

如何安装 @diplodoc/pdf-generator?

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

@diplodoc/pdf-generator 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/diplodoc__pdf-generator 是否存在。

@diplodoc/pdf-generator 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@diplodoc/pdf-generator 可以商用吗?

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

@diplodoc/pdf-generator 的下载量有多少?

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

@diplodoc/pdf-generator 还在维护吗?

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