We're sorry AsposeCloud doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.cloud

Node.js: Resize Image in Word Mail Merge Using Aspose.Words REST API

I see here that images are supported, and the example uses publicly accessible image URLs:


Is there any other way to specify an image, or does the image have to be available over HTTP?

Also - how do size an image if it is just a template tag?

Thanks, Dan


Aspose.Words Cloud Mail Merge feature supports image population from web and storage. Please check the following Node.js code and JSON data to resize the image in Word Mail Merge using Aspose.Words REST API. Furthermore, it seems ExecuteMailMergeOnline API method is not working as expected. It does not use storage at all. However, we have logged a ticket(WORDSCLOUD-1750) to investigate it.

How to Resize Image in Word Mail Merge in Node.js

  • Create a free account at aspose.cloud to get credentials
  • Install Aspose.Words Cloud SDK for Node.js package from NPM
  • Create a script file and import asposewordscloud
  • Instantiate of Aspose.Words Cloud API
  • Upload Mail Merge Template to cloud storage
  • Create ExecuteMailMergeRequest object and pass the image data(path, width and height) as JSON
  • Pass the ExecuteMailMergeRequest to executeMailMerge API method as an argument
  • Run the script file to populate Image in Mail Merge Word Template

Node.js Code to Insert Image in Mail Merge Word Template

const { WordsApi, UploadFileRequest, ExecuteMailMergeRequest } = require("asposewordscloud");
var fs = require('fs');

// Please get your App Key and App SID from https://dashboard.aspose.cloud/#/apps.
wordsApi = new WordsApi("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxx");

const localFile = "C:/Temp/SampleMailMergeTemplate.docx";
const dataFile = "C:/Temp/SampleMailMergeTemplateData.json";

const remoteFileName = "TestExecuteMailMerge.docx";
const resultFileName = "MailMerge_output.docx";
const remoteFolder = "Temp";

//Upload File
const uploadRequest = new UploadFileRequest({
		fileContent: fs.createReadStream(localFile),
		path: remoteFolder + "/" + remoteFileName

wordsApi.uploadFile(uploadRequest).then((resultApi) => {
		}).catch(function(err) {
		// Deal with an error

//Mail Merge
const request = new ExecuteMailMergeRequest({
        name: remoteFileName,
        data: fs.createReadStream(dataFile),
        folder: remoteFolder,
        withRegions: false,
        destFileName: remoteFolder + "/" + remoteFileName

wordsApi.executeMailMerge(request).then((result) => {    
		}).catch(function(err) {
		// Deal with an error

Sample JSON Data:

  "Items": [
    "Caption" : "This is the first caption !!!",
	"Img" : {
		"Url" : "http://upload.wikimedia.org/wikipedia/commons/thumb/e/e0/Nagasakibomb.jpg/300px-Nagasakibomb.jpg",
		"Width" : "100px",
		"Height" : "50px"
	"Caption" : "This is the second caption !!!",
	"Img" : "Images/Nagasakibomb.jpg"

So there is no way to specify size in the template? Size is presentation logic, not data.


We already logged a ticket(WORDSCLOUD-1447) for the requirement to set image size in the template. We have linked your post to the ticket and will notify you as soon as it is resolved.


About WORDSCLOUD-1750, please note ExecuteMailMergeOnline does not support populating images from storage as by design all the online methods don’t use storage. However, if you need to use image files from storage, please consider using the ordinary Mail Merge(ExecuteMailMerge) method.

Secondly, we have also resolved the WORDSCLOUD-1447 ticket. The fix will be included in the upcoming release of Aspose.Words Cloud 21.12.

The issues you have found earlier (filed as WORDSCLOUD-1447,WORDSCLOUD-1750) have been fixed in this update. This message was posted using Bugs notification tool by Ivanov_John