How to Convert Excel to PDF using Java API

How to Convert Excel to PDF using Java API
Convert Excel to PDF in Java using REST API

Excel spreadsheet is one of the most used software applications, developed by Microsoft for Windows. PDF (Portable Document Format) is a reliable, secure, and cross-platform file format. It may contain flat text, structuring elements, annotations, and graphics. You can convert Excel spreadsheets XLSX or XLS to PDF programmatically in Java on the cloud using REST API. There are several reasons why you might want to convert an Excel spreadsheet to a PDF. For example, to protect the data, to share the spreadsheet document, to keep the formatting of the spreadsheet, or to help reduce file size and make it easier to share and store. Therefore, in this article, we will see how to convert Excel to PDF using Java API.

The following topics shall be covered in this article:

Excel to PDF Converter Free download online API – Installation

To export JSON to CSV or large CSV to JSON in java, I will be using the Java SDK of GroupDocs.Conversion Cloud API. This Java library is easy to install and offers a wide range of methods to achieve CSV to JSON and JSON to CSV conversion, without installing any 3rd party software. Java file format conversion API allows you to convert your documents and images of any supported file format to any format you need. Quickly convert between more than 50 types of documents and images online like Word, PDF, PowerPoint, Excel, HTML, CAD, raster images, etc.

However, you can either download the APIs JAR file or install the API using Maven configurations. Add repository and dependency into your project’s pom.xml file. Below are the steps for Maven:

Maven Repository:

<repository>
    <id>groupdocs-artifact-repository</id>
    <name>GroupDocs Artifact Repository</name>
    <url>https://repository.groupdocs.cloud/repo</url>
</repository>
Maven Dependency: 

<dependency>
    <groupId>com.groupdocs</groupId
    <artifactId>groupdocs-conversion-cloud</artifactId>
    <version>22.10</version>
    <scope>compile</scope>
</dependency>

Please obtain your Client ID and Secret from the dashboard before following the mentioned steps. Once you have your ID and secret, add the code snippet in a Java-based application:

How to Convert XLSX to PDF Online in Java using REST API

An Excel spreadsheet can be converted to a PDF file. This helps to keep the formatting and layout of the file and to reduce the file size. Let’s convert Excel to PDF file format by following the steps and code snippets given below:

  1. Upload the Excel file to the Cloud
  2. Convert Excel to PDF using Java
  3. Download the converted PDF file

Upload the File

Firstly, upload the Excel file to the Cloud using the following code sample:

As a result, the uploaded Excel spreadsheet will be available in the files section of your dashboard on the cloud.

Convert Excel into PDF Online using Java

Please follow the steps mentioned below to convert XLSX file to PDF programmatically:

  • Create an instance of ConvertApi
  • Create ConvertSettings instance
  • Set the storage name and input the XLSX file path
  • Now, provide the output file format as “pdf”
  • Next, set the output file path
  • Create ConvertDocumentRequest with convert settings as a parameter
  • Finally, invoke conversion using the ConvertApi.convertDocument() method

The following code example shows how to convert Excel format to PDF file in Java using REST API:

How to convert Excel into PDF Online using Java
Convert Excel into PDF Online using Java

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 Excel Spreadsheet to PDF in Java using Advanced Settings

Please follow the steps mentioned below to convert XLSX file to PDF programmatically:

  • Create an instance of ConvertApi
  • Create ConvertSettings instance
  • Set the storage name and input Excel file path
  • Next, set “pdf” as the output file format
  • Create an instance of the PdfConvertOptions
  • Set various convert options like setFromPage, setPagesCount, setZoom, setImageQuality, setPassword, setHeight, setMarginTop, setDpi, etc.
  • Now set convert options and output file path values
  • Create ConvertDocumentRequest with convert settings as a parameter
  • Finally, get the output file by invoking the ConvertApi.convertDocument() method

The following code snippet shows how to convert Excel file to PDF file online in Java using REST API:

How to convert Excel Spreadsheet to PDF in Java using Advanced Settings
Convert Excel Spreadsheet to PDF in Java using Advanced Settings

Online Excel to PDF Converter Free

How to convert XLSX to PDF online for free? Please try the following free online XLSX to PDF converter, which is developed using the above API.

Conclusion

In this article, you have learned:

  • how to convert Excel format to PDF file in java on the cloud;
  • programmatically upload the Excel file and then download the converted PDF file from the cloud;
  • how to convert Excel to PDF online in java using advanced settings;
  • free Excel to PDF converter online;

You can learn more about GroupDocs.Conversion Cloud API using the documentation, or examples available on GitHub. We also provide an API Reference section that lets you visualize and interact with our APIs directly through the browser.

Finally, groupdocs.cloud is writing new blog articles on different file formats conversions using REST API. So, please stay in touch for the latest updates.

Ask a question

You can put your questions/ questions on how to convert Excel to PDF, via our forum.

FAQs

How do I convert Excel data to PDF in Java?

Please follow this link to learn the Java code snippet for how to convert Excel file to PDF quickly and easily.

How to convert Excel table to PDF in Java using REST API?

Create an instance of ConvertApi, set the values of the convert settings, and invoke the convertDocument method with ConvertDocumentRequest for converting Excel file to PDF.

How to save Excel to PDF free online?

Excel spreadsheet to PDF converter online free allows you to export Excel to PDF file, quickly and easily. Once the conversion is completed, you can download the PDF file.

How do I convert Excel XLSX to PDF online for free?

  • Open online Excel to PDF converter free
  • Click inside the file drop area to upload an Excel sheet or drag & drop an Excel file.
  • Click on Convert Now button, online XLSX to PDF converter will turn Excel table into PDF file.
  • Download link of the output file will be available instantly after converting convert Excel to PDF online.

How to install convert Excel to PDF online library?

Install Excel to PDF converter free download Java library to create, and convert Excel to PDF programmatically.

How do I convert Excel to PDF in windows?

Please visit this link to download the Excel file to PDF converter for free. This offline converter can be used to change Excel spreadsheet to PDF file in windows, using a single click.

See Also

Please visit the following links to learn more about: