DEV Community

Cover image for Convert Excel to PDF in Node.js | Export XLSX to PDF Online with REST API
Aspose for Aspose.Cloud

Posted on Originally published at blog.aspose.cloud

Convert Excel to PDF in Node.js | Export XLSX to PDF Online with REST API

When it comes to sharing or printing spreadsheet data, converting Excel to PDF is the most reliable option. PDF ensures universal readability, preserves the document layout, and supports cross-platform compatibility. With Aspose.Cells Cloud SDK for Node.js, converting XLS or XLSX to PDF becomes seamless, fast, and highly accurate—perfect for developers and enterprises alike.

Why Convert Excel to PDF?

  • Universal Format : PDF files open on any device without formatting issues.
  • Secure : Prevents unauthorized editing while maintaining data integrity.
  • Print-Ready : Ideal for reports, invoices, and financial documents.
  • Cross-Platform Sharing : Viewable on Windows, macOS, Linux, iOS, Android.

In this article, we are going to discuss following topics in more details.

Getting Started with Node.js API

Using Aspose.Cells Cloud for Node.js, you get the capabilities to easily convert an Excel workbook to PDF format. It enables you to transform all major formats including XLS, XLSX, XLSB, XLTX, ODS and many more. For further information, you may consider visiting Supported file formats.

Prerequisites:

  1. Sign up and get your API credentials from the Aspose Cloud Dashboard .
  2. Install the Node.js SDK via npm:
npm install asposecellscloud --save
Enter fullscreen mode Exit fullscreen mode

Node.js Code to Convert Excel to PDF

Please follow the steps specified below to convert your Excel spreadsheet to a .txt file step-by-step:

  1. Create an object of cellsApi class that takes Client ID and Client Secret details as arguments.
  2. Upload the input XLS file using uploadFile(…) method to the cloud storage.
  3. Now invoke the PostWorkbookSaveAs(…)16 method for Excel to PDF format.
const { CellsApi, PostWorkbookSaveAsRequest } = require("asposecellscloud");
const fs = require("fs");
const path = require("path");

const clientId = "YOUR_CLIENT_ID";
const clientSecret = "YOUR_CLIENT_SECRET";

const cellsApi = new CellsApi(clientId, clientSecret);

// Upload file to cloud storage
const localFilePath = "source.xlsx";
const cloudFilePath = "source.xlsx";
await cellsApi.uploadFile(cloudFilePath, fs.createReadStream(localFilePath));

// Set up PDF conversion request
const saveOptions = {
    SaveFormat: "PDF"
};

const request = new PostWorkbookSaveAsRequest({
    name: cloudFilePath,
    saveOptions: saveOptions,
    newfilename: "converted/output.pdf"
});

// Convert to PDF
await cellsApi.postWorkbookSaveAs(request);
console.log("Excel file successfully converted to PDF.");
Enter fullscreen mode Exit fullscreen mode

Excel to PDF

A preview of Excel to PDF conversion with Node.js API

Convert Excel to PDF via cURL

Prefer command-line tools? You can also convert Excel to PDF using the REST API with cURL.

Step 1: Generate Access Token:

curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=CLIENT_ID&client_secret=CLIENT_SECRET" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"
Enter fullscreen mode Exit fullscreen mode

Step 2: Trigger Excel to PDF Conversion: Now we are going to execute PostWorkbookSaveAs method to perform Excel to PDF conversion:

curl -v -X POST "https://api.aspose.cloud/v3.0/cells/{sourceFile}/SaveAs?newfilename=converted.txt&isAutoFitRows=false&isAutoFitColumns=false&checkExcelRestriction=true" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT_Token>" \
-H  "Content-Type: application/json" \
-d "{  \"SaveFormat\": \"TXT\"}"
Enter fullscreen mode Exit fullscreen mode

Replace:

  • sourceFile with input Excel file name.
  • <JWT_TOKEN> with the access token you generated.

Try Free Excel to PDF Converter Online

Experience our Online Excel to PDF Converter for instant results without any coding.

excel to pdf file

Excel to PDF converter App.

Useful Developer Resources

Conclusion

Whether you’re developing an enterprise-grade solution or a simple report automation tool, Aspose.Cells Cloud SDK for Node.js provides a robust and reliable way to convert Excel to PDF online. The RESTful approach makes integration easy, while the SDK ensures precise formatting and fast execution.

Start converting Excel files to PDF now and streamline your document workflows!

Recommended Reading

Please visit the following links to learn more about:

Top comments (0)