npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

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

v2.27.0

Published

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

Downloads

810

Readme

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

| Option | Default | Behavior | | --- | --- | --- | | fidelityPolicy | 'strict' | Rejects unsupported or approximate output. Use 'best-effort' to return available output with diagnostics. | | displayMode | 'proposed' | Includes proposed revisions. Use 'original' for the original content or 'all-markup' to show revisions. | | comments | true | Includes native PDF annotations. Set to false to omit them. | | useSystemFonts | true | Searches standard operating system directories for supported font files. Set to false to disable this search. | | timeoutMs | 60000 | Sets the conversion deadline in milliseconds. | | maxOutputBytes | 67108864 | Limits output to 64 MiB. You can lower this limit. | | maxPages | 10000 | Limits 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

Charts, rotated table-cell text, unsupported equation fallbacks, advanced image effects, some revision presentation, and non-PNG/JPEG 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

| Error | Cause | | --- | --- | | PdfDocumentOpenError | Core rejected the input document. Inspect reason and detail. | | PdfFidelityError | Strict export encountered unsupported or approximate content. Inspect diagnostics. | | ExportResourceError | Cancellation, deadlines, font-policy refusals, or layout failures. Inspect code. | | PdfWorkLimitError | Content exceeded a processing limit. | | PdfOutputLimitError | Encoded bytes exceeded maxOutputBytes. Inspect limit and actual. Extends PdfEncodingError. | | PdfPageLimitError | Layout exceeded maxPages. Inspect limit and actual. Extends RangeError. | | PdfEncodingError | PDF encoding failed. Inspect cause. | | TypeError or RangeError | An 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.