OutOfMemoryException while saving as AsposePDF


I am trying to convert a large excel document to AsposePDF using the following code:

Workbook workbook = new Workbook();
workbook.Save(“E:\asposepdf.xml”, FileFormatType.AsposePdf);

but it uses up a lot of memory and in the end gives a OutOfMemoryException (exception and stack trace pasted at the end)

I noticed that the SDK converts the entire document in memory first and then then writes it all to disk at once. I am wondering if it is possible to have the SDK write to file in small chunks rather than converting the entire document in memory, or any other way to reduce the amount of memory being used during converion…

I have attached a sample dummy xls file as well…

(I am using Aspose.Cells version with .NET 2.0)


Exception of type ‘System.OutOfMemoryException’ was thrown.

Stack Trace:

at xb9d8bb5e6df032aa.

x1110bdd110cdcea4._xaacba899487bce8c(String x5e99b576d2530d13, Int32 x2710752c36f2d14b)
at Aspose.Cells.Converter.x4a76df5fa47c11b2.x72db13fb72c28687(Color x6c50a99faab7d741, Char x4c3e8680a15658ef)
at Aspose.Cells.Pdf.xcd769e39c0788209.x4a9aa5efbc468f04(XmlNode xda5bf54deb817e37, x5c28847d79b605a8 xc4aabdaa13560452, String xb41faee6912a2313, Font x1062e4f06eba0067, Color x8ef2762e422f7380, Double x7fca88fd6467135e)
at Aspose.Cells.Pdf.xcd769e39c0788209.x636457dda93ec7a1(XmlNode xda5bf54deb817e37, x5c28847d79b605a8 xc4aabdaa13560452)
at Aspose.Cells.Pdf.xcd769e39c0788209.x0b596ff29e972dc0(XmlNode xda5bf54deb817e37, x5c28847d79b605a8 xc4aabdaa13560452)
at Aspose.Cells.Pdf.xcd769e39c0788209.xf11889b309a14c60(XmlNode xda5bf54deb817e37, Int32 x3e0a106e44f5f6eb, Int32 x6155c61fc47ceb1a, Int32 xa364300db00bde74, Int32 x433508a87b1e0cdf, Int32 x8e5bc30d03570f25)
at Aspose.Cells.Pdf.xcd769e39c0788209.x7c61808921e5b719(XmlNode xda5bf54deb817e37, x1ac1cdde23ba6178 x5c0499d9a53ac586)
at Aspose.Cells.Pdf.xcd769e39c0788209.x51ee56decc29a9da(XmlNode xc301afa072787492, XmlNode& xda5bf54deb817e37, x1ac1cdde23ba6178 x5c0499d9a53ac586)
at Aspose.Cells.Pdf.xcd769e39c0788209.xf5874e7e871001a1(XmlNode xc301afa072787492, Int32 x69e9b567129e96cb)
at Aspose.Cells.Pdf.xcd769e39c0788209.x6210059f049f0d48()
at Aspose.Cells.Pdf.xcd769e39c0788209.x0acd3c2012ea2ee8(Stream xcf18e5243f8d5fd3)
at Aspose.Cells.Workbook.Save(Stream stream, FileFormatType fileFormatType)


Thanks for providing us details with template file.

Well, we recommend you to try our latest version (4.6.0): http://www.aspose.com/community/files/51/file-format-components/aspose.cells/entry156149.aspx in which we have improved its performance and memory usage.

And, since your spreadsheet has 50k+ rows with certain number of columns in a single worksheet (about 40MB size of the file), huge amount of memory would be required for it and the process would be time consuming and slow as well. So, you need to have a good RAM too. The file (.xml (Aspose.Pdf integrated) file) generated by this process would have big size too. Moreover, in the second phase, when the conversion (xml 2 pdf) is done using Aspose.Pdf for .NET, certain resources would also be consumed and the process would take certain time rendering to .pdf file.

I think you may try to do the following options/steps, it will certainly enhance the performance to certain extent.

1). Try to reduce the size of your file splitting a single file into multiple files.

2). Try to split your dataset into multiple worksheets instead of a single worksheet.

Thank you.

Thanks for the quick and detailed response

I tried with the latest version 4.6.0, and I got the following error while loading the license file:

"The subscription included in this license allows free upgrades until 25
Sep 2008, but this version of the product was released on 09 Dec 2008.
Please renew the subscription or use a previous version of the product."

Do you guys have any trail version license that I can use to test with?


Well, since your license is expired, so, you need to upgrade your subscription to utilize latest versions that are released after your subscription expiry. Alternatively, I think you can obtain/demand a 30 days temporary license to test with it, please check: http://www.aspose.com/corporate/purchase/temporary-license.aspx

Thank you.

Ok, I tried with the latest version but still getting OutOfMemoryException…is it possible for the workbook.Save(“asposepdf.xml”, FileFormatType.AsposePDF) function to stream the data to the file rather than building it all in memory and then writing it to file?


Well, the issue is basically caused by the file size you are processing. Currently we do not support the feature for Saving PDF files directly through stream. But we are working on this feature and we will provide you a beta version for this update soon.

Thank You & Best Regards,


Please try the attached latest fix of Aspose.Cells for .NET. We have supported (beta version) to save PDF file directly from an excel file. As it is a beta release, so we will really appreciate a feedback from your side. Following is the sample code of how to create a PDF directly from Excel file.

Sample Code:-

Workbook workbook = new Workbook();
workbook.Save("C:\\Pdf1.pdf", FileFormatType.Pdf);

Thank You & Best Regards,

Ok tried with the beta version and it converted without running out of memory… :slight_smile: