@danobri
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) => {
console.log('uploaded...');
}).catch(function(err) {
// Deal with an error
console.log(err);
});
//Mail Merge
const request = new ExecuteMailMergeRequest({
name: remoteFileName,
data: fs.createReadStream(dataFile),
folder: remoteFolder,
withRegions: false,
destFileName: remoteFolder + "/" + remoteFileName
});
wordsApi.executeMailMerge(request).then((result) => {
console.log(result.body);
console.log('Completed...');
}).catch(function(err) {
// Deal with an error
console.log(err);
});
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"
}
]
}