Free Support Forum -

Convert DOCX to PDF and save result to local drive in Nodejs using Aspose.Words REST API

I am using node.js and the PUT /words/convert API to convert a docx to a pdf, I get the response body, but am trying to write the body to a pdf file on my computer. I cannot open the file because of corruption issues. Most likely something to do with the encoding


Thanks for your inquiry. Please check following Node.js code to save response body to PDF file. Hopefully it will help you to accomplish the task.

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

// Get App Key and App SID from
wordsApi = new WordsApi("xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxx");

var request = new ConvertDocumentRequest({
                    format: "pdf",
                    document: fs.createReadStream("submission_V7.docx"),
var outputFile = "ConvertWordtoPDF.pdf";
wordsApi.convertDocument(request).then((result) => {    
    fs.writeFileSync(outputFile, result.body);
}).catch(function(err) {
    // Deal with an error

This is awesome. How do I use the same code to GetSections without uploading the document to storage using NodeJS as above?

Thank you!


I’m afraid currently there is no option available to get sections from request body. However, we have logged a feature request WORDSCLOUD-1324 for your requirement. We will update you as soon as it is implemented.