Could not initialize class com.aspose.cells.i72

Hi there,
I’m using 22.7 version.
I’m trying to convert the 2.zip (3.7 MB)
file with the following code -

public static byte[] convertExcelToPDF(ByteArrayInputStream excelInputStream) throws Exception {
        ByteArrayOutputStream outputStreamPdf = new ByteArrayOutputStream();
        try {
            LOGGER.info("Initiating Excel to pdf conversion");
            Workbook workbook = new Workbook(excelInputStream);

            PdfSaveOptions saveOptions = new PdfSaveOptions();
            saveOptions.setAllColumnsInOnePagePerSheet(true);

            workbook.save(outputStreamPdf, saveOptions);

            LOGGER.info("Conversion from Excel to pdf completed");
            return outputStreamPdf.toByteArray();

        } catch (Exception ex) {
            LOGGER.info("Exception occurred while converting Excel to pdf : ", ex);
            throw ex;
        } finally {
            outputStreamPdf.close();
        }
    }

Now, here’s the situation -
It works on my Windows machine.
It throws the following error on our dev environment -
{

"message": "org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class com.aspose.cells.i72"

}

Please help! :slight_smile:

I inspected the jar to find no such class file.

@shaurya.chawla,

I tested your scenario/case using your sample file with latest version of Aspose.Cells for Java v22.7, it works fine and I do not get any exception. I am using Windows 8 with JDK8. Here is my sample code that I am using with your Excel file:
e.g.
Sample code:

         ByteArrayOutputStream outputStreamPdf = new ByteArrayOutputStream();

         System.out.println("Initiating Excel to pdf conversion");
         LoadOptions loadOptions = new LoadOptions(LoadFormat.XLSX);
         File file = new File("f:\\files\\2.xlsx");
         byte[] array = Files.readAllBytes(file.toPath());
         ByteArrayInputStream stream = new ByteArrayInputStream(array);

         Workbook workbook = new Workbook(stream, loadOptions);
         //it also works
         //Workbook workbook = new Workbook(stream);
         
         PdfSaveOptions saveOptions = new PdfSaveOptions();
         saveOptions.setAllColumnsInOnePagePerSheet(true);

         workbook.save(outputStreamPdf, saveOptions);

         System.out.println("Conversion from Excel to pdf completed");
         byte[] bytes = outputStreamPdf.toByteArray(); 

Could you share complete details about your dev. environment, e.g., OS, JDK version, etc.? Also, share complete error stack trace. Moreover, please make sure that on dev. environment, you are using latest version of Aspose.Cells for Java v22.7.

@shaurya.chawla

It seems that there is no font installed for JDK on your dev environment. According to NPE at sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1264) when using install4j caused by font config missing · Issue #693 · adoptium/temurin-build · GitHub, you need to install something. e.g. fontconfig

Thanks for replying,
OS is - RHEL 7.9
We are using Java 11.
@Peyton.Xu will look into the suggested solution. Thanks