Skip to main content

Install

In Node, @reductoai/docx needs Node.js 20.11 or newer.
For the editor UI, also install the editor package:
For a read-only canvas viewer, install the viewer package:
Install these packages with an install token from the Office SDK page in Studio. Studio gives you the two .npmrc lines:

Layout engine (Node)

Your package manager installs one native engine package for your platform as an optional dependency, e.g. @reductoai/docx-engine-linux-x64-gnu. npm, pnpm (also with hoist=false), Yarn (Plug’n’Play and node-modules), Bun and Deno (npm: specifiers) install and load it. The Linux packages need glibc 2.17 or newer. Node.js itself needs a newer glibc, so they load on the AWS Lambda Node.js runtimes (Amazon Linux 2023), Debian 11, RHEL 8 and Ubuntu 20.04. Without a native engine, the library lays out with the bundled engine.wasm: the same engine as WebAssembly, slower. The native engine loads in worker_threads: workers can start, convert and exit one after another or side by side in one process.

Optional native modules (Node)

The Node build uses native modules where they are faster. They are optional; the library uses a slower fallback when a module is missing.

Bundlers

  • The package has a browser export condition. Vite, webpack and esbuild select the browser build when they bundle for a page. You need no alias or polyfill.
  • Browser layout runs in @reductoai/docx/engine.wasm. Vite, webpack and Next.js copy the file into your build. With another bundler, such as esbuild, give its URL. See The layout engine.
  • Vite 7 and older build workers as iife, which the editor’s worker does not fit: set worker: { format: "es" } in vite.config.
  • Keep @reductoai/docx/node out of client code. In Next.js, add @reductoai/docx and @reductoai/portable-fonts to serverExternalPackages so the server bundle keeps native modules on disk.
  • Layout is CPU work. In a page, run it in a Web Worker if the document is large. The editor does this for you (see Editor).

Smoke test

Run it with npx tsx smoke.ts (or compile it first). Open hello.pdf.