Convert Doc to PDF in Node.js

Doc to PDF in Node.js

Node.js is an open-source, cross-platform, back-end JavaScript runtime environment and due to these capabilities, it has become a leading choice of the server-side web development platform. It enabes the developers to use the same tools and paradigms for both server-side and client-side software. Owing to these salient features, we have specifically created Aspose.Words Cloud SDK for Node.js. It enables you to create, manipulate, convert, render and perform a wide variety of operations on Word documents. In this article is, we are going to discuss the conversion of DOC to PDF format, which protects the documents against undesirable modifications.


The first step to getting started with SDK is the installation and is available for download at NPM and GitHub. Among these, the easiest one is through npm. Execute the following command to perform the installation

npm install asposewordscloud

Also please be aware that SDK has the following dependencies which shall be resolved before performing any document processing.

 @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+) 

Cloud subscription

After the installation, the next step is to create an account by visiting Aspose.Cloud dashboard. If you have GitHub or Google account, simply Sign Up. Otherwise, click on the Create a new Account button and provide the required information. Now login to the dashboard using credentials and expand the Applications section from the dashboard and scroll down towards the Client Credentials section to see Client ID and Client Secret details.

Client Credentials

The cURL command approach

Aspose.Words Cloud APIs are developed on REST API architecture and therefore, they can also be accessed via cURL commands over the command line terminal. So in this section, we are going to discuss the steps on how to perform the DOC file to PDF format using the cURL command.

However, before accessing the APIs on the command line terminal, please note that we need to first generate a JWT access token based on Client ID and Client Secret details because the APIs are only accessed by authorized persons.

curl -v "" \
-d "grant_type=client_credentials&client_id=718e4235-8866-4ebe-bff4-f5a14a4b6466&client_secret=388e864b819d8b067a8b1cb625a2ea8e" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

Once the JWT token has been generated, access GetDocumentWithFormat API to perform DOC to PDF conversion.

curl -X GET "" \
-H  "accept: application/octet-stream" \
-H  "Authorization: Bearer <JWT Token>"

DOC to PDF in Node.js

The following steps explain how to perform the conversion of the DOC file already available in cloud storage to PDF format and save the resultant document in the same cloud storage.

  • First of all, create a variable holding Client ID and Client Secret details
  • Secondly, initialize an instance of WordsApi while passing Client ID and Client Secret details as arguments
  • Thrildy, create an object of GetDocumentWithFormatRequest class and define input DOC file name, resultant output format as PDF and name of final output file
  • Finally, call getDocumentWithFormat(..) method of WordsApi class and pass GetDocumentWithFormatRequest object as an argument to initialize the conversion


This article has explained the concepts of MS Word document (DOC) conversion to PDF format using Aspose.Words Cloud SDK for Node.js. In simple few code lines, you get the capabilities to transform the Word document to a PDF that retains its formatting and fidelity on any platform. Please note that using the same approach, other formats such as DOCX, RTF, ODT can also be transformed. Furthermore, please note that all our Cloud SDKs are developed on the Opensource concept, so their complete source code is available for download over GitHub. For further details about product features, you may consider visiting the documentation module.

In case you encounter any issues while using the API or you have any related queries, please feel free to contact us through the Free Product support forum.

Related Article

We also recommend visiting the following links to explore more features on