Word or PDF Mail merge in JavaScript

High-fidelity JavaScript library to execute Mail merge on Word or PDF templates and data from a custom data source

Create personalized documents, emails, and reports with Mail merge API using our solution – powerful JavaScript library. Simply merge Word and PDF templates using JavaScript. The result of the Mail merge operation can be saved in DOCX, PDF, HTML and other popular formats.

View code snippet

Mail merge using JavaScript

Our product provides a powerful Mail merge API to build your own advanced software solution. Whether you need to create personalized emails for clients, generate a report based on the received data set or create a personalized document for any purpose, our product API can easily handle it.

With our Node solution, you can perform a Mail merge operation in JavaScript. To do this, use the merge template in Word, PDF or other file format and the source data.

Note that the Mail merge template must contain the merge fields into which the source data will be inserted after the Mail merge operation is executed.

Automate emails using Mail merge in JavaScript

Use Mail merge to automate email creation and sending bulk emails. To do this, create an appropriate Mail merge template with merge fields and then automate the mailing by substituting data from your source. For example, you can create an email template with Mail merge fields instead of your customer names. Using Mail merge, you can fill in these fields with client names pulled from your data source.

So you get the fast and easy way to create thousands of personalized emails in seconds!

Build reports using JavaScript

You can generate reports with Mail merge in JavaScript. You still need to create a Word, PDF or other file format Mail merge template with merge fields. Such fields will be used to substitute data from the data source and build a report.

Try Mail merge feature using JavaScript

To see how the JavaScript Mail merge operation works using our Node solution, import Word or PDF template with merge fields and data in XML or JSON format. After performing the code, save the merge result generated using our product API in a convenient format – DOCX, HTML, PDF and so on:

Upload a Mail merge template
Run code
Upload a MailMerge data file
Select the target format from the list
import * as fs from "fs";

const wordsApi = new WordsApi("####-####-####-####-####", "##################");

const template = fs.createReadStream("Input1.docx");
const data = fs.createReadStream("Input2.docx");

const executeMailMergeOnline = new model.ExecuteMailMergeOnlineRequest({
    template: template,
    data: data

.then((executeMailMergeOnlineResult) => {
    console.log("Result of ExecuteMailMergeOnline: ", executeMailMergeOnlineResult);
Run code
Copy JavaScript code to the clipboard

How to use Mail merge in Word or PDF documents

  1. Install Aspose.Words Cloud for Node
  2. Add a library reference (import the library) to your JavaScript project
  3. Configure WordsApi using your app keys
  4. Load your Mail merge template and source data
  5. Create a MailMerge request, passing template and data files
  6. Call the executeMailMergeOnline() method, passing the request
  7. Get the result of Mail merge operation as a separate file

JavaScript library to use Mail merge

Install 'Aspose.Words Cloud SDK for Node.js' using NPM package manager. Run npm install asposewordscloud --save from the command line to install the SDK via the NPM package manager. As an alternative, you can manually clone Aspose.Words Cloud SDK for Node.js source code from GitHub and use it in your project. Please follow these Instructions to quickly get the necessary security credentials and access our REST API.

System Requirements

  • @types/request (version 2.48.3+)
  • lodash (version 4.17.15+)
  • lodash.template (version 4.5.0+)
  • request (version 2.88.0+)
  • request-debug (version 0.2.0+)

Refer to the Repository Documentation to see more details.


Subscribe to Aspose Product Updates

Get monthly newsletters and offers directly delivered to your mailbox.

© Aspose Pty Ltd 2001-2024. All Rights Reserved.