Excel spreadsheets are commonly used to store and analyze data in the form of rows and columns. However, in various cases, you need to convert the Excel files to PDF before sharing them over the internet. In order to automate Excel to PDF conversion, this article shows how to convert Excel files to PDF programmatically using Node.js. Furthermore, advanced options to customize the Excel to PDF conversion are also discussed.
- Node.js Excel to PDF Conversion API
- Convert Excel XLSX/XLS to PDF
- Advanced Options for Excel XLSX/XLS to PDF
- Get a Free API License
Node.js Excel to PDF Conversion API
For converting the Excel XLSX/XLS files to PDF, we will use Aspose.Cells for Node.js via Java. It is a spreadsheet manipulation API that lets you create, read, modify, and convert Excel workbooks seamlessly. You can either download the API’s package or install it use the following NPM command.
> npm install aspose.cells
Convert Excel XLSX to PDF in Node.js
The following are the steps to convert Excel XLSX or XLS files to PDF.
- Load the Excel file using Workbook class.
- Convert Excel file to PDF using Workbook.save(string, SaveFormat.PDF) method.
The following code sample shows how to convert an Excel XLSX file to PDF.
Excel File
Converted PDF
Excel XLSX/XLS to PDF – Advanced Options
Aspose.Cells also allows you to control the Excel to PDF conversion using different options. For example, you can set PDF compliance, compression, gridlines style, number of pages per sheet, etc. To customize the conversion, the API provides PdfSaveOptions class.
The following are the steps to convert an Excel file to PDF with advanced options.
- Load the Excel file using Workbook class.
- Create an object of PdfSaveOptions class.
- Set the desired options e.g. PDF compliance using PdfOptions.setCompliance(PdfCompliance) method.
- Save Excel file as PDF using Workbook.save(string, PdfSaveOptions) method.
The following code sample shows how to convert Excel to PDF using advanced options.
Get a Free API License
In order to use the API without evaluation limitations, you can request a free temporary license.
Conclusion
In this article, you have learned how to convert Excel files to PDF within Node.js applications. Furthermore, you have seen how to control Excel to PDF conversion using advanced options. You can explore more about the Node.js Excel API using the documentation. Furthermore, you can contact us via our forum in case of any query.