XLS to PDF using Node.js

Excel to PDF in Node.js

Excel is one of the popular file formats for computation data storage. It is capable of storing data like numbers and formulas, text, and drawing shapes. Furthermore, Excel is part of the Microsoft Office Suite of software, so many users use it to produce the XLS files. Furthermore, owing to its capabilities for storing data in a grid of cells arranged in numbered rows and letter-named columns to organize data manipulations like arithmetic operations, it has become very popular. But in order to view these files, you need to have a specific application installed. Also, various versions of software display the files in different formattings. Therefore, in order to resolve all these issues, the conversion of the file to PDF format is a viable solution because the majority of web browsers on desktops and various free applications on mobile devices conveniently display the PDF documents.

In this article, we are going to discuss the conversion of Excel to PDF conversion using Cloud REST API.

Excel processing SDK

Aspose.Cells Cloud is our award-winning REST API offering the capabilities to create excel files from scratch, edit the content in the existing files and, render the file to formats such as XLSM, HTML, XPS, TIFF, SVG, and much more. However, in this article, we are going to discuss the feature to convert XLS files to PDF format. Please note that we have specifically created a wrapper around Cloud API named Aspose.Cells Cloud SDK for Node.js which provides all the capabilities of REST API within Node.js code.

Excel to PDF using the cURL command

Before proceeding further, let’s discuss the amazing leverage of REST APIs as they can be accessed on any platform using the cURL commands. Since Aspose.Cells Cloud is also developed as per REST architecture, so it can also be accessed using the cURL commands.

However, in order to ensure data integrity and protection, the API is only accessible to authorized users only, so we need to create a Free account subscription on 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

Now we need to generate a JWT access token based on Client ID and Client Secret details as specified on Aspose.Cloud dashboard. Please execute the following command to generate the JWT access 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 we have the JWT token, we need to execute the following cURL command to upload a file from the local system to Cloud storage and then perform the conversion to PDF format.

curl -X PUT "https://api.aspose.cloud/v3.0/cells/storage/file/conditional.xls" \
-H  "accept: application/json" 
-H  "authorization: Bearer <JWT Token>" \
-H  "Content-Type: multipart/form-data" \
-d {"File":{}}
https://api.aspose.cloud/v3.0/cells/storage/file/conditional.xlsx

In case you need to perform the conversion of XLS file already available in Cloud storage to PDF format, please try using the following cURL command:

curl -X GET "https://api.aspose.cloud/v3.0/cells/conditional.xls?format=PDF&isAutoFit=true&onlySaveTable=false&outPath=output.pdf" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>"

Convert Excel to PDF in Node.js

In this section, we are going to discuss the steps and details on how to perform the Excel worksheet conversion to PDF format using Node.js SDK. The first step is to install the SDK on the local system which is available for download at NPM and GitHub. So we are going to run the following command to install the SDK from NPM

npm i asposecellscloud

After the installation, we can execute the following code snippet to perform XLS to PDF conversion using Node.js

  • The first step is to add references of required calsses from asposecellscloud package
  • Secondly, create const objects defining Client ID and Client Secret details
  • Thirdly, create an object of CellsApi class which takes Client ID and Client Secret details as arguments
  • The next step is to read the contents of input XLS file available on local system using createReadStream(…) method of File System Module
  • Now create an instance of UploadFileRequest class and then pass input Stream data to file property
  • In order to upload the file to cloud storage, please call uploadFile(…) method of CellsApi
  • The next step is to create an object of CellsSaveAs_PostDocumentSaveAsRequest(…) class
  • Furthermore, create an instance of PdfSaveOptions class and pass the value of PDF to saveFormat property
  • Finally, call the cellsSaveAsPostDocumentSaveAs(..) method of CellsApi class to initiate the conversion process

Conclusion

In this article, we have discussed the details related to Excel file conversion to PDF format in a simple and convenient manner. The best part is that you can perform the conversion for Free. Yes, you can perform up to 150 document processing requests under free subscription plan and once you are satisfied with the quality and service, you may opt for purchasing the license which can be as low as $0.005 /API call. For more information, you may visit the Pricing section.

Nevertheless, please note that Aspose.Cells Cloud SDK for Node.js is developed according to open-source principles, so the complete source code is available for download at GitHub. In case you encounter any issue while using the API or you have any related queries, please do not hesitate to ask via the Free product support forum.

Related articles

You may consider visiting the following links to learn more about