How to Convert XLSX to PDF using Java

This how-to tutorial walks you through the procedure to convert XLSX to PDF using Java, including the creation of a sample application. By utilizing a popular conversion library, we will demonstrate how to export XLSX to PDF using Java. Additionally, we will provide instructions on configuring the document conversion package to perform the document conversion. This article outlines the necessary steps and provides a code example to assist in converting XLSX files to PDF.

Steps to Convert XLSX to PDF using Java

  1. Utilize the Maven repository to incorporate GroupDocs.Conversion for Java into your project by downloading it
  2. Import the essential classes for XLSX to PDF conversion
  3. Initialize an instance of the Converter class by passing the path of XLSX file to its constructor
  4. Get the desired conversion options by calling Converter.getPossibleConversions method
  5. Call the Convert.save method to save the final PDF to disk

The main steps for implementing the capability to generate PDF from XLSX in Java have been outlined. As you’ll notice, the process only involves a few lines of Java code to perform the document conversion. The provided code example can be used on any standard operating system, such as Windows, macOS, and Linux, as long as Java is installed.

Code to Convert XLSX to PDF using Java

import com.groupdocs.conversion.Converter;
import com.groupdocs.conversion.licensing.License;
import com.groupdocs.conversion.options.convert.ConvertOptions;
public class ConvertXLSXtoPDFusingJava {
public static void main(String[] args) {
// Set License to avoid the limitations of Conversion library
License license = new License();
license.setLicense("GroupDocs.Conversion.lic");
// Import XLSX document
Converter converter = new Converter("input.xlsx");
// Get conversion option for final output document
ConvertOptions xlsxtopdfconvertoptions = converter.getPossibleConversions("pdf")
.getSource().getConvertOptions();
// Save the PDF to disk
converter.convert("ConvertXLSXtoPDFusingJava.pdf", xlsxtopdfconvertoptions);
}
}

In the section above, we provided a comprehensive explanation of the process Java XLSX to PDF, along with a straightforward code example. The code is brief, and the document conversion can be accomplished with only a few API calls. After installing the document conversion library and adjusting the input and output file paths, integrating the above code example into your applications is straightforward.

Earlier, we presented a guide on how to convert XLSX files to CSV format. For more information, please refer to our article on how to convert XLSX to CSV using Java.

 English