Issues converting Excels to PDF


#1

Using the following code:

        try {

            Workbook workbook = new Workbook(filePath);
            PdfSaveOptions opts = new PdfSaveOptions();
            workbook.save(filePath + ".pdf", opts);
        } catch (Exception e) {
            System.out.println("Exception:\n"+ e.toString());
        }

On the following 4 files, I get the following 4 exceptions:


com.aspose.cells.CellsException: 1


com.aspose.cells.CellsException: 1


com.aspose.cells.CellsException: Column width must be between 0 and 255


java.lang.OutOfMemoryError: Java heap space


#2

@russ.nichols,
I have tried your first three files with the latest version but could not observe any issue.
Please try our latest version/fix: Aspose.Cells for Java v19.7.6 (attached)
Aspose_Cells_Java_v19.7.6.zip (6.6 MB)

Regarding the Java heap size issue for “20150126 - D1 Ownership.xlsx”, we were able to observe the issue but we need to look into it more. We have logged the issue in our database for investigation and for a fix. Once, we will have some news for you, we will update you in this topic.

This issue has been logged as

CELLSJAVA-42981 – Exception "Java.lang.OutOfMemoryError: Java heap space" while converting to PDF

#3

@russ.nichols,

We evaluated your issue further.
Well, your issue is because there are more than 80 million pages (lots of blank pages in it) in worksheet “Officers, Jurisdiction & Voting”. You can try using the following code to set print area that with data:

Workbook wb = new Workbook("20150126 - D1 Ownership.xlsx");

Worksheet sheet = wb.getWorksheets().get("Officers, Jurisdiction & Voting");
String maxDataCellName = CellsHelper.cellIndexToName(sheet.getCells().getMaxDataRow(), sheet.getCells().getMaxDataColumn());
sheet.getPageSetup().setPrintArea("A1:"+maxDataCellName);

wb.save(outFile.pdf);

Another way is by skipping the files which contain too many pages. We will provide new API to evaluate the total pages of file before saving to PDF file format.


#4

@russ.nichols,

We add new APIs: WorkbookPrintingPreview.getEvaluatedPageCount() and SheetPrintingPreview.getEvaluatedPageCount() to get page count efficiently in the upcoming fix/version (we will share the Download link to the fix in the next few days or so).
e.g
Sample code:

Workbook wb = new Workbook("20150126 - D1 Ownership.xlsx");
ImageOrPrintOptions imgOpt = new ImageOrPrintOptions();

WorkbookPrintingPreview wp = new WorkbookPrintingPreview(wb, imgOpt);
System.out.println(wp.getEvaluatedPageCount());

SheetPrintingPreview sp = new SheetPrintingPreview(wb.getWorksheets().get("Officers, Jurisdiction & Voting"), imgOpt);
System.out.println(sp.getEvaluatedPageCount());

#5

@russ.nichols,

Please try our latest version/fix Aspose.Cells for Java v19.8 .

Let us know your feedback.


#6

Hi Amit,

Using v19.8 it did fix a few of the issues, but still on z182225.xlsx linked above I get a stack trace:

com.aspose.cells.CellsException: Column width must be between 0 and 255

	at com.aspose.cells.Cells.setColumnWidth(Unknown Source)
	at com.aspose.cells.Cells.setColumnWidthPixel(Unknown Source)
	at com.aspose.cells.Cells.setColumnWidthInch(Unknown Source)
	at com.aspose.cells.zcey.c(Unknown Source)
	at com.aspose.cells.zcey.a(Unknown Source)
	at com.aspose.cells.zcey.a(Unknown Source)
	at com.aspose.cells.zcey.a(Unknown Source)
	at com.aspose.cells.zjq.a(Unknown Source)
	at com.aspose.cells.Workbook.a(Unknown Source)
	at com.aspose.cells.Workbook.save(Unknown Source)

#7

@cemeyer2,
I have tried the conversion of “z182225.xlsx” to PDF using Aspose.Cells for Java 19.8, but could not observe any issue. Output PDF file is generated successfully without any error. Could you please explain the steps to reproduce this issue? I have tried the following sample code in Windows 7 and Eclipse IDE:

Workbook workbook = new Workbook(filePath);
PdfSaveOptions opts = new PdfSaveOptions();
workbook.save(filePath + ".pdf", opts);

#8

I just checked again, still get error. Here is the code I executed:

 @Test
    public void verifyThingsWork() throws Exception {
        String filePath = "/Users/meyer/Downloads/z182225.xlsx";
        Workbook workbook = new Workbook(filePath);

        PdfSaveOptions opts = new PdfSaveOptions();

        workbook.save(filePath + ".pdf", opts);
    }

Here was the stack trace

com.aspose.cells.CellsException: Column width must be between 0 and 255

	at com.aspose.cells.Cells.setColumnWidth(Unknown Source)
	at com.aspose.cells.Cells.setColumnWidthPixel(Unknown Source)
	at com.aspose.cells.Cells.setColumnWidthInch(Unknown Source)
	at com.aspose.cells.zcey.c(Unknown Source)
	at com.aspose.cells.zcey.a(Unknown Source)
	at com.aspose.cells.zcey.a(Unknown Source)
	at com.aspose.cells.zcey.a(Unknown Source)
	at com.aspose.cells.zjq.a(Unknown Source)
	at com.aspose.cells.Workbook.a(Unknown Source)
	at com.aspose.cells.Workbook.save(Unknown Source)
	at Test(Test.java:30)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

My dependencies:

image.png (4.4 KB)

Just to ensure, here is the xlsx that i had cause the issue

https://drive.google.com/file/d/1Y4SNnC5XLlZQolSwAr9twpXVDyrMraNL/view?usp=sharing


#9

@cemeyer2,

Thanks for the template file, sample code and screenshot.

I tested using the following sample code with template file using v19.8.0 on my pc (OS: Windows8, JDK1.8, etc.), it works fine and I do not get any exception. It generates a PDF file with size more than 150MB and over 200k pages. Please make sure that you are using latest version/fix: Aspose.Cells for Java v19.8. You may also print the version number for Aspose.Cells for Java API, see the sample code segment that I am using:
e.g
Sample code:

String filePath = "f:\\files\\z182225.xlsx";
		 System.out.println(CellsHelper.getVersion());
	        Workbook workbook = new Workbook(filePath);

	        PdfSaveOptions opts = new PdfSaveOptions();

	        workbook.save(filePath + ".pdf", opts);

#10

Hi

I ran my code again and verified I am on 19.8.0. I am using Mac osx, but tried with both jdk 8 and 11 and both had the same failures:

code:

    @Test
    public void verifyThingsWork() throws Exception {
        long startTime = System.currentTimeMillis();
        try {
            String filePath = "/Users/meyer/Downloads/z182225.xlsx";
            System.out.println("Java version: " + System.getProperty("java.version"));
            System.out.println("aspose cells version: " + CellsHelper.getVersion());
            Workbook workbook = new Workbook(filePath);
            PdfSaveOptions opts = new PdfSaveOptions();
            workbook.save(filePath + ".pdf", opts);
        } catch (Exception e) {
            System.out.println("Duration: " + (System.currentTimeMillis() - startTime));
            throw e;
        }
    }

both had the same Column Width must be between 0 and 255 error


#11

@cemeyer2,

Thanks for providing further details.

Could you try your scenario/ case on Windows os and how it goes?. We will also try to test it on your mentioned platform and get back to you with more details.


#12

Hi,

I ran it on windows and did not see the error. I then ran it on linux (which is where this code will eventually run in production) and did notice the same error as on osx.

So, it seems this problem is only surfacing on non-windows systems


#13

@cemeyer2,
Yes, you are right as this issue is not reproduced in Windows environment however we were able to observe the issue in macOS but we need to look into it more. We have logged the issue in our database for investigation and for a fix. Once, we will have some news for you, we will update you in this topic.

This issue has been logged as

CELLSJAVA-42991 – "Column width must be between 0 and 255" exception while convertingExcel to PDF in macOS

#14

@cemeyer2,

This is to inform you that we have fixed your issue (logged earlier as “CELLSJAVA-42991”) now. We will soon provide you the fixed version after performing QA and incorporating other enhancements and fixes.


#15

@cemeyer2,
Please try latest fix/version and let us know your feedback.
aspose-cells-19.8.3.zip (6.6 MB)


#16

@ahsaniqbalsidiqui

Sorry, this file is private. Only visible to topic owner and staff members.


#17

@cemeyer2,
Please try to download from following link:


#18

19.8.3 fixed it, thanks!


#19

The issue with heap space on 20150126 - D1 Ownership.xlsx is still present though. The stack trace looks like:

java.lang.OutOfMemoryError: Java heap space

at java.util.Arrays.copyOf(Arrays.java:3181)
at java.util.ArrayList.grow(ArrayList.java:265)
at java.util.ArrayList.ensureExplicitCapacity(ArrayList.java:239)
at java.util.ArrayList.ensureCapacityInternal(ArrayList.java:231)
at java.util.ArrayList.add(ArrayList.java:462)
at com.aspose.cells.b.a.a.zf.a(Unknown Source)
at com.aspose.cells.zvy.a(Unknown Source)
at com.aspose.cells.zvy.a(Unknown Source)
at com.aspose.cells.zvy.a(Unknown Source)
at com.aspose.cells.zvy.a(Unknown Source)
at com.aspose.cells.zvy.a(Unknown Source)
at com.aspose.cells.zcfi.a(Unknown Source)
at com.aspose.cells.zcfi.a(Unknown Source)
at com.aspose.cells.zcfi.a(Unknown Source)
at com.aspose.cells.zjq.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.save(Unknown Source)

#20

@PeteLee,
This workbook shows around 78376635 pages when print preview feature is called. This shows that this file is too large to be rendered to PDF, that is why getEvaluatedPageCount() is provided. You may please use this function to get the evaluated page count and then decide about rendering it. We are afraid that this “Java heap space” issue cannot be resolved and you may use above mentioned function prior to conversion for avoiding this exception.