We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

System.OutOfMemoryException on PDF Save

On our server, we are getting a System.OutOfMemoryException for the following code with the attached file, and when I run it locally on my machine, it just seems to get stuck and not complete. Do you know why?


try
{
Workbook workbook = new Workbook(@“C:\Example.xlsx”);

PdfSaveOptions options = new PdfSaveOptions(SaveFormat.Pdf);
options.AllColumnsInOnePagePerSheet = true;
options.OnePagePerSheet = true;
workbook.Save(@“C:\Example.pdf”, options); //this line hangs
}
catch (Exception ex)
{
throw;
}

Hi,


Thanks for providing us template file and sample code.

Well, I checked your template file and found that one of the worksheets named “RB - historical data” (last sheet) in the file has 3646 pages in total. As you are forcing via Aspose.Cells APIs to make one page of this very long sheet, so Aspose.Cells would continuously try to render this big sheet in single page which is not possible. It would consume more and more memory for the big process. I am afraid, you cannot render this big worksheet to render into a single page in PDF, you cannot render one page for the big sheet even in MS Excel either. We suggest you to kindly do not set the PDF option(s) (e.g OnePagePerSheet, AllColumnsInOnePagePerSheet) for the big sheets (e.g "“RB - historical data”) in the workbook while rendering to PDF file format.

Please try as suggested above and let us know your feedback.

Thank you.

Do you have a suggestion for determining the maximum size sheet I could render using the above PDF options?

Hi,


Yes, sure, you may evaluate the total number of pages a worksheet has, see the sample code snippet (below) for your reference:
e.g
Sample code:


ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();<o:p></o:p>

imgOptions.PrintingPage = PrintingPageType.IgnoreBlank;

Aspose.Cells.Rendering.SheetRender sheetRender = new Aspose.Cells.Rendering.SheetRender(worksheet, imgOptions);

int sheetPageCount = sheetRender.PageCount;

...........

Hope, this helps a bit.

Thank you.