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());