Work with Word Documents in Node.js

Node.js DOCX

Aspose.WordsCloud Node.js SDK

Work with Word Documents in Node.js

 

Open, create, edit, merge, split, compare and convert a Word document in Node.js. It's easy for Node.js developers to manipulate Microsoft Word documents.
Aspose.Words Cloud Node.js package is a fast, easy and powerful conversion library to convert files including PDF to Word and Word to PDF. It can generate a converted document according to the targeted file format specifications.

Note: API works on any environment that supports Node.js including Linux, Windows and OSX.


  • Main
  • Convert
  • Structure
  • Content
  • Tables
  • MailMerge
  • Other
  • Plugins
  •  

Requirements

Node.js 4.8.7 or higher

Supported Document Formats

You can both read and write documents in: DOCX, DOC, RTF, DOTX, DOT, ODT, OTT, XML, HTML, MHTML, TXT, PDF.
The write-only formats are: XPS, OpenXPS, PS, JPEG, PNG, BMP, SVG, TIFF, EMF, PCL, EPUB.
For more details, please check Supported File Formats.

Supported features to edit documents in Node.js

There are different tasks which you can perform using API to manipulate data and files such as:

  • Split a Word document into multiple smaller files, or to extract pages to a new file.
  • Create a Word document with Node.js.
  • Read data from a Word document using Node.js.
  • Extract content from Word files in Node.js.
  • Extract data from tables in a Word document.

Edit and convert documents

Node.js API allows you to edit a word document and apply the following:

  • Insert a table.
  • Add paragraphs.
  • Extract text.
  • Insert an image.
  • Insert a watermark image.
  • Get hyperlinks.
  • Add a header or a footer.

You can export a Word document into the specified format and make several conversion tasks for different file formats in Node.js such as:

  • Convert Word to PDF.
  • Convert Word to TXT.
  • Convert HTML to PDF
  • Convert DOCX to PNG.
  • Convert Word to EPUB.

Note: Check our free online converter.

Compare documents

Node.js API allows you to recognize differences between two versions of a Word document. It helps in avoiding the long process of comparing text in two documents line by line. It accurately identifies important changes to text without additional conversion steps, even if the versions of the document are in different formats such as DOCX, PDF or image files.

Note: Check our document comparison online.

Working with paragraphs

You can work with paragraphs in Node.js and apply many operations such as:

  • Get all paragraphs that are included in a document or in a section.
  • Add space before and space after a paragraph.
  • Use line spacing to set the amount of space between lines within a paragraph.
  • Set first-line indent to the left side of the first line of a paragraph.
  • Choose between several types of alignment such as Centered, Left-Justified and Right-Justified.
  • Keep text together by using KeepTogether and KeepWithNext properties.

Working with sections

You can create section/chapter, headers and footers in a Word document using node.js. Sections are the Word feature that controls page number formatting, headers and footers, orientation (portrait/landscape), margins and columns.
Section break usually is placed after the title page, copyright page, dedication page, table of contents, chapter 1, chapter 2, and so on. These section breaks will create a page break between each of those sections.
Using our Node.js library, you can perform the following operations on sections:

  • Insert, delete or update a section break.
  • Add section content.
  • Copy sections between documents.
  • Get a list of sections or a particular section from a Word document.
  • Read or update page setup of a section.

Convert PDF to Word in Node.js

The following code sample shows how to convert PDF to DOCX in the Cloud and save the result to a local file:

Convert PDF to DOCX

const { WordsApi, ConvertDocumentRequest } = require("asposewordscloud");
const fs = require('fs');

var appSid = "####-####-####-####-####";
var appKey = "##################";

var wordsApi = new WordsApi(appSid, appKey);

var fileName = "sample.pdf";
var request = new ConvertDocumentRequest({
	format: "docx",
	document: fs.readFileSync(fileName),
});

wordsApi.convertDocument(request).then((result) => {
	fs.writeFile('sample.docx', result.body, (err) => {
		if (err) throw err;
		console.log('Successfully converted');
	});
}).catch(function(err) {
	console.log('Error:', err);
});

Advanced Features

How to open and edit a DOCX document in Nodejs

  1. Install Nodejs package.
  2. Go to the Aspose Cloud Dashboard.
  3. Create a new Account to access all applications and services or Sign In to your account.
  4. Click on My Apps tab to get App KEY and App SID.
  5. Upload a DOCX file to the Cloud Storage.
  6. Check Developer Guide to edit a DOCX file in Node.js.

Support and Learning Resources