惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
大猫的无限游戏
大猫的无限游戏
J
Java Code Geeks
MongoDB | Blog
MongoDB | Blog
Martin Fowler
Martin Fowler
GbyAI
GbyAI
Microsoft Azure Blog
Microsoft Azure Blog
Recent Announcements
Recent Announcements
F
Fortinet All Blogs
B
Blog
U
Unit 42
B
Blog RSS Feed
D
DataBreaches.Net
Google DeepMind News
Google DeepMind News
人人都是产品经理
人人都是产品经理
腾讯CDC
量子位
酷 壳 – CoolShell
酷 壳 – CoolShell
V
Visual Studio Blog
博客园 - 聂微东
MyScale Blog
MyScale Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 三生石上(FineUI控件)
Engineering at Meta
Engineering at Meta

Inside Nutrient

A guide to the invisible work behind documents Introducing Nutrient Documents for Salesforce: Native document generation and signing Document AI vs. traditional OCR: Choosing between OCR, AI, and hybrid pipelines PDF SDK compliance and security evaluation checklist for enterprise teams (2026) Invariant Corp replaces paper processes with Nutrient Workflow and scales without limits What is process mapping? A complete guide Nutrient vs. Conga Composer for Salesforce document generation (2026) Document routing: How to automate document distribution The CTO’s AI playbook: Why accountability architecture beats orchestration Compliance workflow automation: Why built-in compliance is table stakes Workflow diagrams: Examples, symbols, and how to build one that actually runs Digital forms: Replace paper forms with automated workflows Approval workflow software: How to automate approvals Why document-centric automation is different The CEO’s AI playbook: Why decision architecture beats model selection Nutrient SDK product updates for Q1 2026 PDF redaction verification: How to prove sensitive data is permanently removed What is a VPAT? The complete guide to accessibility conformance reports What is PDF/UA? The accessible PDF standard explained Salesforce eSignatures: Generate, sign, and track documents in one flow Online document viewer: Options, tradeoffs, and how to embed one Document viewer for web apps: React, Vue, Angular (2026) Best document viewers in 2026: A buyer’s guide How to edit a PDF in Python: Add text, images, and annotations Nutrient advances Workflow platform with agentic AI for enterprise-grade speed and consistency in document-heavy operations How to create a Salesforce quote template from opportunity data The business case for accessibility: Five ways it drives enterprise value Python PDF library comparison (2026): 7 libraries for developers Why your AI agent hallucinates PDF table data PDF.js limitations: When to upgrade to a commercial PDF SDK
Build a powerful JavaScript document viewer and editor
Hulya Masharipov · 2024-09-10 · via Inside Nutrient

Managing documents within web applications is essential for organizations across various industries, including healthcare, engineering, and finance. This tutorial guides you through setting up a robust JavaScript-based document viewer and editor using the Nutrient Document Authoring SDK. You’ll learn how to handle Microsoft Word (DOCX) files directly in your browser, without the need for external software.

Introducing the Nutrient Document Authoring SDK

Nutrient’s Document Authoring SDK offers a comprehensive solution for building an advanced document viewer and editor within your web application. With a familiar WYSIWYG (what you see is what you get) interface, similar to Google Docs or Microsoft Word, the SDK allows users to open, edit, and export complex documents, maintaining perfect fidelity across browsers and when exported to PDF or DOCX. This makes it an ideal tool for handling documents accurately and efficiently.

Key benefits of using the Document Authoring SDK

Below, we’ve outlined a few key benefits of using the Document Authoring SDK.

A familiar and intuitive editing experience

The SDK provides a page-based layout for rich text editing that resembles the interfaces of popular document editing tools. This familiarity helps users quickly adapt to the editor, enhancing productivity and user satisfaction. With advanced features like complex tables, floating images, headers, footers, and sophisticated numbering, it goes beyond the capabilities of standard text areas and other rich text libraries.

Perfect fidelity and consistency across platforms

One of the standout features of the Document Authoring SDK is its ability to ensure documents look exactly the same across all browsers and when exported in PDF or DOCX formats. This is particularly important for industries that require precision, such as legal, finance, and publishing. The SDK is the only product on the market that guarantees 100 percent WYSIWYG fidelity in PDF exports, streamlining workflows and reducing errors caused by document inconsistencies.

Seamless integration and customization

The SDK is designed with our fully customizable Baseline UI, allowing developers to easily integrate it into any web application and customize it to fit their specific needs. This flexibility ensures that the document viewer and editor align with the overall design and functionality of your platform, providing a consistent user experience.

Getting started with the Document Authoring SDK

In this tutorial, you’ll learn how to set up the Nutrient Document Authoring SDK to create a powerful JavaScript-based document viewer and editor that supports DOCX files. You’ll use Vite(opens in a new tab) as your development environment to ensure a fast and efficient setup.

Step 1 — Creating a new Vite project

First, create a new Vite project. Vite offers a modern development experience with fast project setup:

npm create vite@latest my-document-app

cd my-document-app

Select vanilla for the framework and JavaScript for the variant. This command sets up a new Vite project in the specified directory.

Step 2 — Installing the Nutrient Document Authoring SDK

Next, install the Nutrient Document Authoring SDK, which provides the tools needed to implement the document editor and viewer:

npm install @nutrient-sdk/document-authoring

The SDK leverages WebAssembly (Wasm) to deliver high performance, enabling in-browser document editing without the need for server-side processing.

Step 3 — Integrating the document editor and viewer

To integrate the editor and viewer into your project, follow the steps outlined below.

  1. In index.html, create a <div> element where the editor will be rendered:

<div

id="editor"

style="position: relative; width: 100%; height: 100vh; border: 1px solid #dcdcdc;"

></div>

  1. In main.js, add the following JavaScript code to import the Nutrient library and set up the editor:

import { createDocAuthSystem } from "@nutrient-sdk/document-authoring";

(async () => {

const docAuthSystem = await createDocAuthSystem();

const editor = await docAuthSystem.createEditor(

document.getElementById("editor"),

{

document: await docAuthSystem.createDocumentFromPlaintext("Hello world!"),

},

);

})();

This code initializes the document authoring system, creates an editor instance, and loads a sample document.

Step 4 — Running the Vite development server

Start the Vite development server to view your editor in action:

Open your browser and go to the provided local URL to see the JavaScript document editor and viewer in operation.

Working with DOCX files

The Nutrient Document Authoring SDK supports importing and exporting DOCX files, allowing for seamless document handling.

Importing DOCX files

To load a DOCX file into your editor, use the importDOCX method:

// Assuming the `docAuthSystem` instance is initialized.

const document = await docAuthSystem.importDOCX(await fetch("/document.docx"));

const editor = await docAuthSystem.createEditor(

document.getElementById("editor"),

{ document },

);

This code fetches a DOCX file from the specified URL and loads it into the editor.

To see this in action, you can try out the demo to experience the document loading and editing functionality directly.

Explore Demo

Exporting DOCX files

To export the current document as a DOCX file, use the exportDOCX method:

// Assuming the `editor` instance is initialized.

const currentDoc = editor.currentDocument();

const doc = await currentDoc.exportDOCX();

The exported DOCX file is returned as an ArrayBuffer, which you can then save or use as needed.

Working with PDF files

The Nutrient Document Authoring SDK also supports exporting documents to PDF without additional setup. Use the exportPDF method:

// Assuming the `editor` instance is initialized.

const currentDoc = editor.currentDocument();

const doc = await currentDoc.exportPDF();

This method returns the PDF file as an ArrayBuffer, allowing you to handle it as required.

First-class JSON support with DocJSON

DocJSON is the internal format used by the Nutrient Document Authoring SDK for high portability and integration with modern web technologies. It retains key features of existing formats while being more compatible with JSON-based workflows.

Working with DocJSON in the editor

DocJSON is used when loading and saving documents. It’s designed for easy customization and integration.

Loading DocJSON:

// Assuming the `docAuthSystem` instance is initialized.

const document = await docAuthSystem.loadDocument(

await fetch("./document.json").then((response) => response.json()),

);

const editor = await docAuthSystem.createEditor(

document.getElementById("editor"),

{ document },

);

Saving DocJSON:

// Assuming the `editor` instance is initialized.

const currentDoc = editor.currentDocument();

const docObj = await currentDoc.saveDocument();

console.log("JS object", docObj);

const docJSON = await currentDoc.saveDocumentJSONString();

console.log("JSON string", docJSON);

Here, the document is saved as both a JavaScript object and a JSON string.

Example DocJSON format

Here’s a simple example of a DocJSON document:

{

"type": "https://www.nutrient.io/document-authoring/persistence/container",

"version": 1,

"container": {

"document": {

"body": {

"sections": [

{

"elements": [

{

"type": "p",

"elements": [

{

"type": "r",

"text": "Hello world!"

}

]

}

]

}

]

}

}

}

}

The example illustrates the basic structure of a DocJSON document. This JSON format is designed to represent documents in a straightforward manner, with formatting styles and page setups being optional and defaulting to standard settings if not specified.

In this example, the JSON format is version 1 and organizes documents as a body containing sections. Each section includes various elements, which can be of different types and include inline content.

Specifically, this document consists of a single paragraph with one text run displaying “Hello world!”. Unlike HTML, where elements can be nested, DocJSON represents inline elements like text runs as a flat sequence.

Conclusion

Setting up a JavaScript-based DOCX editor and viewer with the Nutrient Document Authoring SDK and Vite is efficient and effective. This solution enables seamless handling of DOCX files directly in the browser, eliminating the need for external tools.

The SDK supports DocJSON for easy integration and customization, making it a versatile choice for web development needs.

To explore more features or discuss how the SDK can fit your specific requirements, contact our Sales team for further assistance. Try the demo(opens in a new tab) to see the SDK in action and get started with your document editing and viewing solution today!

FAQ

The Nutrient Document Authoring SDK is a comprehensive toolkit for building a document viewer and editor directly within web applications. It offers a WYSIWYG (what you see is what you get) interface, similar to popular tools like Google Docs and Microsoft Word, allowing users to open, edit, and export DOCX documents with perfect fidelity. Key features include support for complex tables, floating images, headers, footers, sophisticated numbering, and 100 percent accurate PDF exports.

The SDK guarantees perfect fidelity by rendering documents exactly the same way across all browsers and when exporting to DOCX or PDF. It uses advanced rendering algorithms and internal document representations to maintain accurate formatting, layout, and styles, ensuring the exported documents look identical to their in-browser versions.

The SDK supports importing DOCX files and exporting documents in both DOCX and PDF formats. This makes it versatile for various use cases where you need to handle DOCX input and PDF output.

DocJSON is the internal format used by the Nutrient Document Authoring SDK for document editing and storage. It offers high portability and is designed for easy integration with modern web technologies. DocJSON retains key features of traditional document formats while allowing seamless integration with JSON-based workflows.