Saving Excel to PDF needs 9GB RAM also after removing empty rows and empty columns

I have an excel workbook with a size of 11kb. If I go to the print preview in excel it says that it would like to print 41.000 pages, because of empty rows.

I open this workbook with aspose cells and remove the empty columns and empty rows.
Saving this to PDF needs some time and 9GB of RAM. The resulting PDF has a size of approximately 84Mbyte.

I open and save the workbook with the following code:
image.png (78.9 KB)

How can I optimize the workbook, so that it just prints 1 page?

Here is the workbook: Unterschiede_Richter_T&C.zip (8.5 KB)

I’ve fixed this in setting the print range anew:

                    // We redefine the print range, because deleting the empty columns/rows still keeps the old print range
                    var maxRange = sheet.Cells.MaxDisplayRange;
                    if (maxRange != null)
                    {
                        sheet.PageSetup.PrintArea = maxRange.Address;
                    }

Is this the correct way or can you suggest a better one?

@HauptlorenzAG,

Yes, you are doing it fine now. Please note, since there are lots of formatted (empty) cells right through up to the end row (1048576) and DeleteBlankRows/DeleteBlankColumns won’t remove formatted cells. So, it is best to specify the printable area so only that area would be rendered in the output PDF.

1 Like