doc to pdf

Convert DOC to PDF online using 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. Owing to these salient features, we have specifically developed Aspose.Words Cloud SDK for Node.js, enabling you to create, manipulate, and convert, Word documents to a variety of formats. In this article, we are going to discuss the conversion of DOC to PDF.

Now in order to use the SDK, we need to first install it and it’s available for download at NPM and GitHub. Please execute the following command to perform the installation from npm.

npm install asposewordscloud

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

 [@types/request][6] (version 2.48.3+)
 [lodash][7] (version 4.17.15+)
 [lodash.template][8] (version 4.5.0+)
 [request][9] (version 2.88.0+)
 [request-debug][10] (version 0.2.0+) 

After the installation, the next step is to create a free 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 obtain your personalized Client Credentials. We are going to use these details in the following sections.

DOC to PDF in Node.js

The following steps explain the details on how to perform the conversion of DOC file already available in cloud storage to PDF format. After the conversion, the resultant file is saved in 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
  • Thirdly, create an object of GetDocumentWithFormatRequest class and define the input DOC file name, resultant output format as PDF, and name of the final output file
  • Finally, call the getDocumentWithFormat(..) method of WordsApi class and pass the GetDocumentWithFormatRequest object as an argument to initialize the conversion

Word to PDF using cURL Commands

As Aspose.Words Cloud API is developed on REST architecture, so we can access them via cURL commands over the command line terminal. Now before accessing the APIs on the command line terminal, we need to first generate a JWT access token based on Client ID and Client Secret details. Please execute the following command to generate the JWT token.

curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-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 "https://api.aspose.cloud/v4.0/words/GetStyles.doc?format=pdf&outPath=Resultant.pdf" \
-H  "accept: application/octet-stream" \
-H  "Authorization: Bearer <JWT Token>"

Conclusion

This article has explained the details of developing a Word to PDF converter using Node.js. With few code lines, we can transform DOC to PDF while retaining its formatting and fidelity. Please note that using the same approach, other formats such as DOCX, RTF, and ODT can also be converted to PDF. Nonetheless, all our SDKs are developed under the Opensource concept, so their complete source code is available for download over GitHub.

You may learn about other product features by 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