ZipException - invalid entry size - while converting xlsx to pdf

Hello

While trying to convert an Excel file (attached), I’m getting the following error -
java.util.zip.ZipException: invalid entry size (expected 0 but got 1053 bytes)
at java.base/java.util.zip.ZipInputStream.readEnd(ZipInputStream.java:398) ~[na:na]
at java.base/java.util.zip.ZipInputStream.read(ZipInputStream.java:197) ~[na:na]
at java.base/java.util.zip.ZipInputStream.skip(ZipInputStream.java:250) ~[na:na]
at com.aspose.cells.a.d.s.a(Unknown Source) ~[aspose-cells-22.6.jar:22.6.0]
at com.aspose.cells.a.d.s.(Unknown Source) ~[aspose-cells-22.6.jar:22.6.0]
at com.aspose.cells.a.d.k.a(Unknown Source) ~[aspose-cells-22.6.jar:22.6.0]
at com.aspose.cells.a.d.c1.(Unknown Source) ~[aspose-cells-22.6.jar:22.6.0]
at com.aspose.cells.a.d.c1.a(Unknown Source) ~[aspose-cells-22.6.jar:22.6.0]
at com.aspose.cells.p4m.a(Unknown Source) ~[aspose-cells-22.6.jar:22.6.0]
at com.aspose.cells.z8.a(Unknown Source) ~[aspose-cells-22.6.jar:22.6.0]
at com.aspose.cells.z8.a(Unknown Source) ~[aspose-cells-22.6.jar:22.6.0]
at com.aspose.cells.Workbook.a(Unknown Source) ~[aspose-cells-22.6.jar:22.6.0]
at com.aspose.cells.Workbook.(Unknown Source) ~[aspose-cells-22.6.jar:22.6.0]
at com.ms.clientdocs.dgdocmanager.utility.PdfUtility.ConvertExcelToPDF(PdfUtility.java:165) ~[main/:na]

XLSX file compressed inside of 7z sample.7z (2.8 KB)

I’m using Aspose.Cells 22.6
And the following code -
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 : {0}", ex);
        throw ex;
    } finally {
        outputStreamPdf.close();
    }

@shaurya.chawla,

Thanks for the template file.

I am able to reproduce the issue using the following sample code with your template file. I found an exception “java.util.zip.ZipException: invalid entry size (expected 0 but got 1053 bytes)” on loading the file into workbook object model from streams. It works fine if we use filePath though.
e.g.
Sample code:

        LoadOptions loadOptions = new LoadOptions(LoadFormat.XLSX);
        File file = new File("f:\\files\\sample.xlsx");
        byte[] array = Files.readAllBytes(file.toPath());
        ByteArrayInputStream stream = new ByteArrayInputStream(array);

        Workbook workbook = new Workbook(stream, loadOptions);

        //Workbook workbook = new Workbook("f:\\files\\sample.xlsx");

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

        workbook.save("f:\\files\\out1.pdf", saveOptions);

I have logged a ticket with an id “CELLSJAVA-44725” for your issue. We will look into it soon.

Once we have an update on it, we will let you know.

Thanks for acknowledging Amjad. Hoping for a fix soon! :slight_smile:

Hey Amjad, just curious to know - when can I expect this bug to be fixed? Is there a tentative timeline? I believe it’s a bug related to handling of zip streams inside of Aspose logic.

@shaurya.chawla,

No, it is not an issue of Aspose.Cells for handling zip input stream, but the issue of java’s zip apis for processing such kind of archive. You will get the same exception by iterating entries from the ZipInputStream without any reference to Aspose.Cells.

If possible, please load the workbook from file directly instead of the InputStream. If you have to load the workbook from InputStream, currently you may use JVM option:
Aspose.Cells.ZipTool=TEMPFILE
for your application. With this option, when we processing such kind of abnormal archive, we will try to use temp file to load workbook.

Also we are implementing our own zip function now, with the new implementation we can solve such kind of issues. Hopefully we can include the new function in next official version and your issue will be solved then.

Thanks for your reply @johnson.shi
I see. Eager to have the zip functionality onboarded in our solution. :slight_smile:

@shaurya.chawla,

We are pleased to inform you that we have sorted it out in Aspose.Cells API. The fix will be included in the next release (Aspose.Cells for Java v22.7) which is scheduled in the second week of July 2022. You will also be notified when the next version is released.

1 Like

The issues you have found earlier (filed as CELLSJAVA-44725) have been fixed in this update. This message was posted using Bugs notification tool by Peyton.Xu

Thanks! Just a question here - My firm uses aspose through an internal repo that fetches JARs from Maven. How can I get the latest artifact published on the maven central repository?

@shaurya.chawla,

See the document on how to install Aspose.Cells for Java (latest version) from maven repository for your reference.