Excel spreadsheets are widely used to maintain invoices, ledgers, inventory, accounts, and other reports. Excel to PDF conversion allows sharing Excel data with others in a portable form. As a Node.js developer, you can easily convert your Excel Spreadsheets to PDF documents programmatically on the cloud. In this article, you will learn how to convert Excel Spreadsheets to PDF using Node.js.
The following topics shall be covered in this article:
- Excel to PDF Conversion REST API and Node.js SDK
- Convert Excel to PDF using a REST API in Node.js
- Convert Specific Excel Spreadsheets to PDF in Node.js
- Excel to PDF Conversion with Advanced Options
- Convert Excel to PDF without using Cloud Storage
- Convert Excel to PDF and Add Watermark
Excel to PDF Conversion REST API and Node.js SDK
For converting XLSX to PDF, I will be using the Node.js SDK of GroupDocs.Conversion Cloud API. The API allows you to convert your documents to any format you need. It supports the conversion of over 50 types of documents and images such as Word, Excel, PowerPoint, PDF, HTML, JPG, PNG, CAD. It also provides .NET, Java, PHP, Ruby, Android, and Python SDKs as its document conversion family members for the Cloud API.
You can install GroupDocs.Conversion Cloud to your Node.js application using the following command in the console:
npm install groupdocs-conversion-cloud
Please get your Client ID and Client Secret from the dashboard before you start following the steps and available code examples. Once you have your ID and secret, add in the code as shown below:
Convert Excel to PDF using a REST API in Node.js
You can convert Excel Spreadsheets to PDF documents on the cloud by following the simple steps given below:
- Upload the XLSX file to the Cloud
- Convert Excel to PDF using Node.js
- Download the converted PDF file
Upload the Excel File
Firstly, upload the XLSX file to the cloud using the following code sample:
As a result, the uploaded XLSX file will be available in the files section of your dashboard on the cloud.
Convert Excel to PDF using Node.js
You can easily convert XLSX to PDF document programmatically by following the steps mentioned below:
- Create an instance of the ConvertApi
- Create an instance of the ConvertSettings
- Set the XLSX file path
- Assign “pdf” to format
- Provide the output file path
- Create ConvertDocumentRequest with ConvertSettings
- Convert by calling the ConvertApi.convertDocument() method with ConvertDocumentRequest
The following code example shows how to convert Excel Spreadsheet to a PDF document using a REST API in Node.js.
Download the Converted File
The above code sample will save the converted PDF file on the cloud. You can download it using the following code sample:
Convert Specific Excel Spreadsheets to PDF in Node.js
You can convert specific Excel Spreadsheets to PDF documents programmatically by following the steps mentioned below:
- Create an instance of the ConvertApi
- Create an instance of the ConvertSettings
- Set the XLSX file path
- Assign “pdf” to format
- Provide output file path
- Create an instance of PdfConvertOptions
- Provide specific Spreadsheets to convert
- Set PdfConvertOptions
- Create ConvertDocumentRequest with ConvertSettings
- Convert by calling the ConvertApi.convertDocument() method with ConvertDocumentRequest
The following code example shows how to convert a specific Excel Spreadsheet to a PDF document using a REST API in Node.js.
Excel to PDF Conversion with Advanced Options
Please follow the steps mentioned below to convert XLSX to PDF document with some advanced settings:
- Create an instance of the ConvertApi
- Create an instance of the ConvertSettings
- Set the XLSX file path
- Assign “pdf” to format
- Provide output file path
- Create an instance of the SpreadsheetLoadOptions
- Set various load options such as hideComments, onePagePerSheet, etc.
- Create an instance of the PdfConvertOptions
- Set various convert options such as displayDocTitle, fromPage, pagesCount, margins (top, left, right, bottom), etc.
- Create ConvertDocumentRequest with ConvertSettings
- Convert by calling the ConvertApi.convertDocument() method with ConvertDocumentRequest
The following code example shows how to convert Excel Spreadsheet to a PDF document with advanced convert options.
Convert Excel to PDF without using Cloud Storage
You can convert Excel Spreadsheets to PDF documents without using cloud storage by following the steps mentioned below:
- Create an instance of the ConvertApi
- Read input XLSX file from local path
- Create ConvertDocumentDirectRequest
- Provide target format and the input file path as input parameters
- Get results by calling the convertDocument_Direct()_ method with ConvertDocumentDirectRequest
- Save the output file to the local path using FileStream.writeFile() method
The following code example shows how to convert Excel Spreadsheet to a PDF document without using cloud storage. It means you will pass the input file in the request body and receive the output file in the API response.
Convert Excel to PDF and Add Watermark
You can convert Excel Spreadsheets to watermarked PDF documents by following the steps mentioned below:
- Create an instance of the ConvertApi
- Create an instance of the ConvertSettings
- Set the XLSX file path
- Assign “pdf” to format
- Provide output file path
- Create an instance of the WatermarkOptions
- Set Watermark Text, Color, Width, Height, etc.
- Define the PdfConvertOptions and assign WatermarkOptions
- Create ConvertDocumentRequest with ConvertSettings
- Convert by calling the ConvertApi.convertDocument() method with ConvertDocumentRequest
The following code example shows how to convert Excel Spreadsheet to a PDF document and add a watermark to the converted PDF document using a REST API in Node.js.
Try Online
Please try the following free online XLSX to PDF conversion tool, which is developed using the above API. https://products.groupdocs.app/conversion/xlsx-to-pdf
Conclusion
In this article, you have learned how to convert Excel to PDF documents on the cloud. You have also learned how to add a watermark to the converted PDF document using Node.js. Moreover, you have learned how to convert Excel Spreadsheets to PDF documents without using cloud storage. Furthermore, you have learned how to programmatically upload the XLSX file on the cloud and then download the converted file from the cloud. You can learn more about GroupDocs.Conversion Cloud API using the documentation. We also provide an API Reference section that lets you visualize and interact with our APIs directly through the browser. In case of any ambiguity, please feel free to contact us on the forum.