XLSX to JPG conversion in Java is a common need when you want to display spreadsheet data as images. GroupDocs.Conversion Cloud SDK for Java offers a simple REST‑based library that lets you render Excel worksheets directly to JPG files. This guide walks you through the required setup, shows a complete code example, demonstrates async processing with cURL, and provides performance tips for handling large workbooks.

Steps to XLSX to JPG Conversion in Java

  1. Add Maven Dependency: Include the SDK in your pom.xml so the library is available at compile time.
<dependency>
    <groupId>com.groupdocs</groupId>
    <artifactId>groupdocs-conversion-cloud</artifactId>
    <version>23.12</version>
</dependency>
  1. Initialize the Conversion Client: Create an instance of ConversionApi with your client credentials.
import com.groupdocs.conversion.cloud.api.ConversionApi;
import com.groupdocs.conversion.cloud.client.ApiClient;
import com.groupdocs.conversion.cloud.configuration.Configuration;

Configuration config = new Configuration();
config.setClientId("YOUR_CLIENT_ID");
config.setClientSecret("YOUR_CLIENT_SECRET");

ConversionApi conversionApi = new ConversionApi(new ApiClient(config));
  1. Configure Conversion Options: Set the output format to JPG, choose a resolution, and enable async processing if desired.
import com.groupdocs.conversion.cloud.model.requests.ConvertDocumentRequest;
import com.groupdocs.conversion.cloud.model.ConvertOptions;
import com.groupdocs.conversion.cloud.model.JpgConvertOptions;

JpgConvertOptions jpgOptions = new JpgConvertOptions();
jpgOptions.setResolution(300);          // 300 DPI for high quality
jpgOptions.setQuality(90);              // JPEG quality 0‑100
jpgOptions.setAsync(true);              // Enable async conversion

ConvertOptions options = new ConvertOptions();
options.setOutputFormat("JPG");
options.setJpgOptions(jpgOptions);
  1. Execute the Conversion: Build a ConvertDocumentRequest with the source XLSX file and the options, then call the API.
import java.io.File;

File sourceFile = new File("sample.xlsx");
ConvertDocumentRequest request = new ConvertDocumentRequest(sourceFile, options);
String jobId = conversionApi.convertDocument(request);
System.out.println("Conversion started, job ID: " + jobId);
  1. Download the Result: Poll the job status until it is completed, then download each generated JPG.
import com.groupdocs.conversion.cloud.model.JobStatus;
import com.groupdocs.conversion.cloud.model.responses.JobStatusResponse;

while (true) {
    JobStatusResponse statusResponse = conversionApi.getJobStatus(jobId);
    JobStatus status = statusResponse.getStatus();
    if (status == JobStatus.COMPLETED) break;
    Thread.sleep(2000); // wait 2 seconds before next poll
}
conversionApi.downloadResult(jobId, new File("output/"));
System.out.println("JPG files saved to output folder.");

For more details on request objects, see the API reference.

Generate JPG from XLSX in Java - Complete Code Example

This example demonstrates a full end‑to‑end conversion that loads an XLSX workbook, converts each worksheet to a separate JPG, and saves the images locally.

package com.example.conversion;

import com.groupdocs.conversion.cloud.api.ConversionApi;
import com.groupdocs.conversion.cloud.client.ApiClient;
import com.groupdocs.conversion.cloud.configuration.Configuration;
import com.groupdocs.conversion.cloud.model.requests.ConvertDocumentRequest;
import com.groupdocs.conversion.cloud.model.ConvertOptions;
import com.groupdocs.conversion.cloud.model.JpgConvertOptions;
import com.groupdocs.conversion.cloud.model.responses.JobStatusResponse;
import com.groupdocs.conversion.cloud.model.JobStatus;

import java.io.File;

public class XlsxToJpgDemo {
    public static void main(String[] args) throws Exception {
        // 1. Configure client
        Configuration config = new Configuration();
        config.setClientId("YOUR_CLIENT_ID");
        config.setClientSecret("YOUR_CLIENT_SECRET");
        ConversionApi api = new ConversionApi(new ApiClient(config));

        // 2. Prepare conversion options
        JpgConvertOptions jpgOpts = new JpgConvertOptions();
        jpgOpts.setResolution(300);
        jpgOpts.setQuality(90);
        jpgOpts.setAsync(true); // async conversion

        ConvertOptions convOpts = new ConvertOptions();
        convOpts.setOutputFormat("JPG");
        convOpts.setJpgOptions(jpgOpts);

        // 3. Create request
        File source = new File("input/sample.xlsx");
        ConvertDocumentRequest request = new ConvertDocumentRequest(source, convOpts);

        // 4. Start conversion
        String jobId = api.convertDocument(request);
        System.out.println("Job started, ID: " + jobId);

        // 5. Wait for completion
        while (true) {
            JobStatusResponse statusResp = api.getJobStatus(jobId);
            if (statusResp.getStatus() == JobStatus.COMPLETED) break;
            Thread.sleep(2000);
        }

        // 6. Download JPG files
        api.downloadResult(jobId, new File("output/"));
        System.out.println("Conversion finished. JPG files are in the output folder.");
    }
}

Note: This code example demonstrates the core functionality. Before using it in your project, make sure to update the file paths (input/sample.xlsx, output/) to match your actual locations, verify that all required dependencies are properly installed, and test thoroughly in your development environment. If you encounter any issues, please refer to the official documentation or reach out to the support team for assistance.

Convert Excel to Image Using cURL

The following cURL commands illustrate how to perform the same XLSX to JPG conversion using the REST API. Replace placeholder values with your actual credentials and file names.

  1. Obtain Access Token
curl -X POST "https://api.groupdocs.cloud/v1.0/oauth/token" \
     -H "Content-Type: application/json" \
     -d '{"client_id":"YOUR_CLIENT_ID","client_secret":"YOUR_CLIENT_SECRET"}'
  1. Upload the XLSX File
curl -X POST "https://api.groupdocs.cloud/v1.0/storage/file/upload" \
     -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
     -F "file=@sample.xlsx"
  1. Start Async Conversion
curl -X POST "https://api.groupdocs.cloud/v1.0/conversion/convert" \
     -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
     -H "Content-Type: application/json" \
     -d '{
           "sourceFilePath": "sample.xlsx",
           "outputFormat": "JPG",
           "options": {
               "resolution": 300,
               "quality": 90,
               "async": true
           }
         }'
  1. Check Job Status (replace JOB_ID with the value returned from the previous step)
curl -X GET "https://api.groupdocs.cloud/v1.0/conversion/jobs/JOB_ID/status" \
     -H "Authorization: Bearer YOUR_ACCESS_TOKEN"
  1. Download the Resulting JPG Files
curl -X GET "https://api.groupdocs.cloud/v1.0/conversion/jobs/JOB_ID/result" \
     -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
     -o output.zip

For a full list of parameters, see the official API documentation.

Installing and Configuring GroupDocs.Conversion Cloud SDK for Java

Add the SDK to your project with Maven, then configure your client credentials.

# Add the dependency (already shown in the Steps section)
mvn install com.groupdocs:groupdocs-conversion-cloud
// Example configuration (same as in the Steps section)
Configuration config = new Configuration();
config.setClientId("YOUR_CLIENT_ID");
config.setClientSecret("YOUR_CLIENT_SECRET");

You can download the latest JAR files from the download page.

Conversion Options for XLSX to JPG

Several options let you fine‑tune the generated images.

OptionDescriptionExample
ResolutionDPI of the output image. Higher values improve quality but increase file size.jpgOpts.setResolution(300);
QualityJPEG compression level (0‑100).jpgOpts.setQuality(90);
Page RangeConvert specific worksheets only.jpgOpts.setPageRange("1-3");
AsyncRun conversion in background and poll for completion.jpgOpts.setAsync(true);

Each property is part of JpgConvertOptions in the SDK. Refer to the API reference for the full list.

Improving Conversion Speed and Memory Usage

  1. Stream Worksheets - Process one worksheet at a time by enabling async mode; this prevents the whole workbook from loading into memory.
  2. Adjust Resolution - Use the lowest acceptable DPI for your use case; 150‑200 DPI is often sufficient for web previews.
  3. Batch Requests - When converting many files, send them in parallel batches limited by your server’s CPU and network capacity.
  4. Reuse ApiClient - Create a single ConversionApi instance and reuse it across multiple conversions to avoid repeated authentication overhead.

Applying these tips can reduce conversion time by up to 40 % for large Excel files.

Conclusion

XLSX to JPG conversion in Java becomes straightforward with the GroupDocs.Conversion Cloud SDK for Java. By following the steps above, you can render each worksheet as a high‑quality JPG, leverage async processing for better scalability, and apply performance optimizations for large workbooks. Remember to obtain a proper license for production deployments; pricing details are available on the product page, and you can start with a temporary license to evaluate the library. Integrate this capability into your applications to provide fast visual previews of Excel data without relying on client‑side Office installations.

FAQs

How do I perform XLSX to JPG conversion in Java using GroupDocs?
Use the ConversionApi class to upload an XLSX file, set JpgConvertOptions (resolution, quality, async), and call convertDocument. The SDK returns a job ID that you can poll until the JPG files are ready.

Can I convert large Excel workbooks without running out of memory?
Yes. Enable async conversion and set a reasonable resolution. The SDK processes worksheets sequentially, keeping memory usage low.

Is asynchronous conversion supported for XLSX to JPG?
The SDK provides an async flag in JpgConvertOptions. When set to true, the API returns a job ID, allowing you to check status and download results later.

Do I need a special license to use the conversion features in production?
A valid GroupDocs.Conversion Cloud license is required for production use. You can start with a temporary license from the temporary license page before purchasing a full subscription.

Read More