@docx-editor.dev/docx-to-pdf

中文文档
2.38.0发布于 2026/11/16LicenseRef-EigenPal-Pro-Evaluation-1.0TypeScriptESM + CJS构建来源已验证近 30 天下载 4969

Convert DOCX to PDF on Node.js with searchable text, embedded fonts, and comments.

原始使用文档
文档目录12 节
  1. Before you begin
  2. Install the package
  3. Convert a document
  4. Reuse a layout
  5. Configure output
  6. Fonts
  7. Comments
  8. Supported content
  9. Limitations
  10. Errors and resource limits
  11. Developer guides
  12. Run the demo

DOCX Editor by EigenPal

DOCX to PDF

@docx-editor.dev/docx-to-pdf converts DOCX documents to PDF on Node.js. It uses Core's pagination, font resolution, and positioned glyphs to produce searchable text.

The package uses the EigenPal Pro License. Production use requires a commercial agreement.

Before you begin

Use Node.js 20.16.0 or later in the 20.x release line, or Node.js 22.3.0 or later. The converter needs WebAssembly and its packaged font assets. Install a compatible @docx-editor.dev/core peer alongside the converter. Keep one Core copy in your application.

Install the package

npm install @docx-editor.dev/docx-to-pdf @docx-editor.dev/core

For Chinese, Japanese, or Korean text, supply suitable fonts or install the optional @docx-editor.dev/fonts-cjk package. The converter finds the package without configuration.

If you previously relied on bundled CJK coverage, add the optional package to your production dependencies. For installation and deployment details, see Configure PDF fonts.

Convert a document

import { readFile, writeFile } from 'node:fs/promises';
import { exportPdf } from '@docx-editor.dev/docx-to-pdf';

const source = await readFile('document.docx');
const result = await exportPdf(source, {
  displayMode: 'proposed',
  comments: true,
});

await writeFile('document.pdf', result.bytes);

Conversion preserves the source DOCX. Browser applications must send the document to a Node.js server for conversion.

Reuse a layout

Use openDocumentForExport and exportPdfFrom to reuse font resolution and layout. The session also works with Markdown's exportMarkdownFrom. Dispose the session after all exports, including failed exports. For an example, see Compare PDF and Markdown conversion.

Configure output

OptionDefaultBehavior
fidelityPolicy'strict'Rejects unsupported or approximate output. Use 'best-effort' to return available output with diagnostics.
displayMode'all-markup'Shows tracked insertions and deletions. Use 'proposed' for the text with all changes accepted or 'original' for the original content.
commentstrueIncludes native PDF annotations. Set to false to omit them.
useSystemFontstrueSearches standard operating system directories for supported font files. Set to false to disable this search.
timeoutMs60000Sets the conversion deadline in milliseconds.
maxOutputBytes67108864Limits output to 64 MiB. You can lower this limit.
maxPages10000Limits output pages after layout. You can lower this limit.
signal—Cancels conversion through an AbortSignal.

The result includes bytes, pageCount, layoutRevision, displayMode, fontResolution, diagnostics, and timings. Timings report milliseconds spent opening the document, laying out pages, painting content, and encoding the PDF. Each result owns its byte buffer.

Fonts

Use fonts to provide font sources before the installed and packaged sources. Use fallbackFonts to add sources after the packaged fonts. The exporter also reads embedded fonts before using a generic substitute for an unresolved family. Use lastResortFonts after embedded fonts and before generic substitutes.

glyphFallbacks specifies an ordered list of fonts for missing glyphs. The defaults cover symbols, Arabic, Hebrew, mathematics, and color emoji. They also cover CJK text when @docx-editor.dev/fonts-cjk is installed. Emoji from a COLR font retain their palette colors and extractable text.

fontPolicy controls font-source failures and family coverage. fidelityPolicy: 'strict' rejects generic substitutions that can change pagination. fidelityPolicy: 'best-effort' uses those substitutes and reports them. Inspect result.fontResolution for selected faces and source failures.

For optional fallback rejections, see Separate font policy from PDF policy.

For custom font files and policy choices, see Configure PDF fonts.

Comments

Comments become range highlights or text notes. PDF viewers determine whether they display authors, dates, replies, and resolved state. Cross-page comments create an annotation on each affected page. Comments without a visible anchor become labeled notes on the first page.

Editing PDF annotations does not update the DOCX.

Supported content

  • Searchable multilingual text, small caps, text decorations, and tab leaders.
  • Arabic joining across formatting runs and logical text order for Arabic, Persian, and Hebrew text extraction.
  • Synthetic bold and italic when selected font faces lack those variants.
  • Static TrueType and CFF fonts, including selected faces from font collections.
  • Page sizes, page frames, headers, footers, footnotes, and endnotes.
  • Text and image list markers, paragraph fills, and paragraph borders.
  • Table text, shading, and resolved borders.
  • Textboxes and structured equations.
  • Supported vector shapes, horizontal and vertical lines, and outlines that retain their full width.
  • PNG and JPEG images with cropping, transforms, alpha transparency, and fixed opacity.
  • Links, destinations, document metadata, and comments.

The converter reads PNG and JPEG images even when DOCX metadata declares another supported raster format. Supported declarations include PNG, JPEG, GIF, BMP, and WebP.

Limitations

The converter includes the drawing module from @docx-editor.dev/pro/drawing, so charts, DrawingML diagrams, shape effects, VML text paths, and EMF and WMF pictures render. Treemap, sunburst, and map charts, and charts that combine a pie or radar plot with other plot types, do not render. Such a chart exports its saved fallback picture when it has one. Otherwise, it is left out with a drawing diagnostic, so the default strict export refuses the document. Drawings that the module cannot render, rotated table-cell text, unsupported equation fallbacks, some revision presentation, and other unsupported media produce diagnostics. Brightness and grayscale adjustments are not supported.

The writer rejects variable fonts, missing glyphs, prohibited embedding, fonts that prohibit subsetting, and font containers that cannot be encoded. Tagged PDF, PDF/A, encryption, and forms are not supported.

Errors and resource limits

ErrorCause
PdfDocumentOpenErrorCore rejected the input document. Inspect reason and detail.
PdfFidelityErrorStrict export encountered unsupported or approximate content. Inspect diagnostics.
ExportResourceErrorCancellation, deadlines, font-policy refusals, or layout failures. Inspect code.
PdfWorkLimitErrorContent exceeded a processing limit.
PdfOutputLimitErrorEncoded bytes exceeded maxOutputBytes. Inspect limit and actual. Extends PdfEncodingError.
PdfPageLimitErrorLayout exceeded maxPages. Inspect limit and actual. Extends RangeError.
PdfEncodingErrorPDF encoding failed. Inspect cause.
TypeError or RangeErrorAn argument is invalid or a size limit was exceeded.

The writer compresses content streams and embeds font subsets. It retains layout records and font data until conversion finishes. Core's resource limits also apply.

Cancellation is checked between layout, paint, and encoding batches. Synchronous font and image operations cannot be interrupted mid-call. For a hard deadline or heap limit, run conversion in a worker and configure resourceLimits.maxOldGenerationSizeMb.

Developer guides

Run the demo

From the repository root, run:

bun install
bun run dev:pdf

Open http://127.0.0.1:5180. For upload limits, server configuration, and production commands, see the demo README.

版本与发布记录

@docx-editor.dev/docx-to-pdf 共发布 30 个版本,首次发布于 2026/09/24;过去 12 个月发布了 30 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.38.0latest2026/11/16今天
2.38.0-canary.20261116033356.sha-2662bd1canary2026/11/16今天
2.38.0-canary.20261115032819.sha-05856f62026/11/151 天前
2.38.0-canary.20261114032659.sha-cdc64af2026/11/142 天前
2.38.0-canary.20261113032851.sha-e2cbc552026/11/133 天前
2.37.02026/11/115 天前

关于 @docx-editor.dev/docx-to-pdf 的常见问题

@docx-editor.dev/docx-to-pdf 是什么?

Convert DOCX to PDF on Node.js with searchable text, embedded fonts, and comments.

如何安装 @docx-editor.dev/docx-to-pdf?

在项目目录运行 npm install @docx-editor.dev/docx-to-pdf,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@docx-editor.dev/core(~2.38.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@docx-editor.dev/docx-to-pdf 支持 TypeScript 吗?

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

@docx-editor.dev/docx-to-pdf 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@docx-editor.dev/docx-to-pdf 需要什么版本的 Node.js?

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

@docx-editor.dev/docx-to-pdf 可以商用吗?

@docx-editor.dev/docx-to-pdf 使用 LicenseRef-EigenPal-Pro-Evaluation-1.0 许可。声明的许可为 LicenseRef-EigenPal-Pro-Evaluation-1.0,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@docx-editor.dev/docx-to-pdf 的下载量有多少?

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

@docx-editor.dev/docx-to-pdf 还在维护吗?

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