excel to pdf online

Java REST API to convert Excel Workbook to PDF.

Excel files are widely used for managing data, calculations, and reports, but sharing them in their native format can pose compatibility and formatting challenges. Converting these files to PDF ensures that the content remains consistent, secure, and easily viewable across various devices and platforms. This article explores how to achieve this using a Java REST API, providing developers with a reliable and efficient solution to streamline this essential document conversion process.

REST API for Excel to PDF Conversion

Aspose.Cells Cloud SDK for Java is a robust and efficient tool designed to simplify the conversion of Excel spreadsheets into PDF format. This SDK leverages the power of a RESTful API to handle file conversions with precision and ease, making it an excellent choice for cloud-based and automated workflows.

Installation

In order to use the Cloud SDK, we need to add the following Maven dependencies to our pom.xml file:.

<repositories>
    <repository>
        <id>AsposeJavaAPI</id>
        <name>Aspose Java API</name>
        <url>https://repository.aspose.cloud/repo/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-cells-cloud</artifactId>
        <version>24.9</version>
    </dependency>
</dependencies>

Or you can download the latest version from the Aspose Repository.

The second important step is to obtain your client credentials from cloud dashboard. If you do not have an existing account, simply create a free account by following the instructions specified in the quick start article.

Convert Excel to PDF in Java

The following Java code demonstrates how to convert an Excel workbook to PDF format using Java REST API:

CellsApi api = new CellsApi(clientId,clientSecret);

Create an instance of CellsApi while providing client credentials as input arguments.

api.uploadFile("input.xlsx", file, "basic");

Upload the input XLSX to cloud storage using uploadFile(…) method.

File response = api.cellsWorkbookGetWorkbook(name,  password,format, 
			isAutoFit, onlySaveTable, null,"basic",  "Resultant.pdf","basic", null);

Finally, call the method cellsWorkbookGetWorkbook(…) to initiate the conversion operation.

excel to pdf preview

A preview of Excel to PDF conversion.

The input Excel workbook used in above example can be downloaded from:

XLSX to PDF using cURL Commands

Aspose.Cells Cloud, combined with cURL commands, provides a quick and efficient way to convert Excel files to PDF format. This cloud-based solution ensures high-quality conversions while preserving the original formatting, including tables, charts, and layouts. With cURL, you can execute API calls directly from the command line, eliminating the need for additional software installations.

The first step in this method is to generate a JWT access token using the following command:

curl -v "https://api.aspose.cloud/connect/token" \
 -X POST \
 -d "grant_type=client_credentials&client_id=XXXXXXX-b195-426c-85f7-XXXXXXXX&client_secret=XXXXXXXXXXXXXXXXXXXXXXXXX" \
 -H "Content-Type: application/x-www-form-urlencoded" \
 -H "Accept: application/json"

Now that we have the JWT token, we need to execute the following command to convert Excel workbook to PDF formats.

curl -v "https://api.aspose.cloud/v3.0/cells/{sourceFile}/SaveAs?newfilename={myResultant}&isAutoFitRows=false&isAutoFitColumns=false&checkExcelRestriction=false" \
-X POST \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}" \
-H "Content-Type: application/json" \
-d "{ \"SaveFormat\": \"pdf\",}"

Replace sourceFile with the name of input excel file (available in the cloud storage), myResultant with the name of resultant PDF file and accessToken with JWT access token generated above.

Conclusion

In this article, we have learned that Aspose.Cells Cloud offers a seamless, reliable, and efficient solution to handle this task with ease. Its powerful features, such as high-quality output, customization options, and cloud-based convenience, make it an invaluable tool for modern applications. Try Aspose.Cells Cloud SDK for Java today and experience the difference it can make in your development journey. Sign up for a free trial to get started!

Please visit the following links to learn more about: