Excel to TIFF method causes NoClassDefFoundError

I have a Spring Boot maven project that uses Aspose Total (trial version).

I have a test method which ouputs the following:

java.lang.NoClassDefFoundError: com/sun/media/imageio/plugins/tiff/TIFFDirectory

at com.aspose.cells.zqc.a(Unknown Source)
at com.aspose.cells.zqc.a(Unknown Source)
at com.aspose.cells.zcnc.a(Unknown Source)
at com.aspose.cells.WorkbookRender.toImage(Unknown Source)

The method basically does the following:

        Workbook workbook = new Workbook(<absolute path to a xls or xlsx file>);
        WorkbookRender workbookRenderer = new WorkbookRender(workbook, options);
        workbookRenderer.toImage(<absolute path to a tiff file that should be created>);

What is the problem here?
Is there a dependency missing to the aspose total dependency?

@stsakas,

Yes, you may download and use the following Java dependencies APIs:
Java Advanced Imaging API

  • jai_core.jar
  • jai_imageio.jar

One possible link to download the JAI APIs from Oracle can be:
Java Advanced Imaging (JAI) package

Hope, this helps a bit.

Thanks for your reply. Importing the jars fixed the problem i mentioned but now i face another one.

I iterate on a list of excel files (both xls and xlsx) and convert them to tiff files. Here is the code:

    ImageOrPrintOptions options = new ImageOrPrintOptions();
    options.setOnePagePerSheet(true);
    options.setImageType(ImageType.TIFF);
    options.setHorizontalResolution(300);
    options.setVerticalResolution(300);
    options.setTiffCompression(com.aspose.cells.TiffCompression.COMPRESSION_CCITT_4);

    for (String filename: filenames) {
    Workbook workbook = new Workbook(<absolute path to a xls or xlsx file>);
    WorkbookRender workbookRenderer = new WorkbookRender(workbook, options);
    workbookRenderer.toImage(<absolute path to a tiff file that should be created>);
    }

Problem 1: This method has a really strange behavior. There are few times that the tiff output files are fine but most of the time they are corrupted (the code remains the same!). Here is a screenshot when the are corrupted:
Screenshot 2022-04-05 101540.png (3.1 KB)

Also, i noticed that they get either converted successfully or corrupted all together.

Problem 2: For a specific xls file, i get the following output:

Exception in thread “main” java.lang.OutOfMemoryError: Java heap space
at java.desktop/java.awt.image.DataBufferInt.(DataBufferInt.java:75)
at java.desktop/java.awt.image.Raster.createPackedRaster(Raster.java:467)
at java.desktop/java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1032)
at java.desktop/java.awt.image.BufferedImage.(BufferedImage.java:333)
at com.aspose.cells.b.a.b.za.(Unknown Source)
at com.aspose.cells.a.b.zcc.a(Unknown Source)
at com.aspose.cells.zcnc.a(Unknown Source)
at com.aspose.cells.zqc.a(Unknown Source)
at com.aspose.cells.zcnc.a(Unknown Source)
at com.aspose.cells.WorkbookRender.toImage(Unknown Source)

At some point i deleted the line
options.setOnePagePerSheet(true);
and then run the code successfully by chance. The output tiff file was a 450 pages tiff file while the excel had around 7 sheets. There must be a problem with the size of each sheet in this excel file. How do i check the size of the sheets of the excel file in order to prevent the conversion and not get an exception? The excel file is not a huge document. Most of its content is empty cells.

@stsakas,

Good to know that your original issue (“java.lang.NoClassDefFoundError: com/sun/media/imageio/plugins/tiff/TIFFDirectory”) is sorted out by importing the JAI APIs.

Could you please zip and attach your template XLSX file, we will check it soon.

Please do not set OnePagePerSheet option if there are too many pages.
Please note the fastest way to get evaluated pages in the sheet at first:

SheetPrintingPreview sheetPrintingPreview = new SheetPrintingPreview(workbook.getWorksheets().get(0), options);

.....

//don't set OnePagePerSheet if there are too many pages, the threshold is dependent on your environment.
if(sheetPrintingPreview.getEvaluatedPageCount() < 50)
{
    options.setOnePagePerSheet(true);
}
//...
// your code goes  here
//......

Hope, this helps a bit.