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

Free Support Forum - aspose.cloud

How To Convert DOCX to PDF Purely Online in Node.js Using Aspose.Words REST API

Hi, the SDK examples that I have seen for converting a .docx to a .pdf format all seem to indicate that the file has to be uploaded in the request. Is there a way to convert a .docx that has already been uploaded, without first downloading it, using the cloud SDK?

@thebirdmanloves

You can convert DOCX to PDF purely online in Node.js using GetDocumentWithFormat API method of Aspose.Words REST API. Please check the sample code as follows for reference.

Code to Convert DOCX to PDF Online JavaScript

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

const convert = async () => {
// Initiate Aspose.Words REST API
// Please get your Client ID and Client Secret from https://dashboard.aspose.cloud/.
wordsApi = new WordsApi("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx", "xxxxxxxxxxxxxxxxxx");


const remoteFileName = "Sample.docx";
const resultFileName = "Sample.pdf";

// Convert DOCX to PDF
try {
const request = new SaveAsRequest({
                    name: remoteFileName,
                    saveOptionsData: new SaveOptionsData({
                        saveFormat: "pdf",
                        fileName: resultFileName,
                    })
                    //folder: remoteFolder,
		    //storage:"MyDB_Storage"
                });

const docToPDFResponse = await wordsApi.saveAs(request);
console.log(docToPDFResponse.body); 
} catch (err) {
throw err;
}
}

convert()
.then(() => {
console.log("Word document converted successfully");
})
.catch((err) => {
console.log("Error occurred while converting the Word document:", err);
})
1 Like

Thanks @tilal.ahmad! That has sorted it.

1 Like