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

Free Support Forum - aspose.com

System.OutOfMemory Exception

I have a good one for you. I am using ASPOSE.PDF (v 6.3) to extract pages out of an existing PDF and create new, separate PDF documents from a large existing PDF document. The existing PDF has bookmarks that I use to determine when to create new PDF files and which pages to use. This has been working fine for a little over a month. Yesterday my client finally found a way to break it by adding in PDF files that, I think, are too large. This particular PDF file that I am parsing is a 250 MB PDF file. I get errors in a couple locations; and it isn’t consistent.

I try running this document through my dev system and the first time I hit the error was loading the document:

private Document m_pdfDocument;
m_pdfDocument = new Document(ExhibitFile);

“ExhibitFile” is a string to the path of the PDF document. The first time I ran a test I get the error “Exception of type ‘System.OutOfMemoryException’ was thrown.” on the second line of code setting the Document = new Document.

So I stopped the debugger, took some notes, did a few things then tried again. The second time I got the same error but on a different line of code. The second time it actually loaded the document, but trhew the error as I was adding the pages to the new document.

private string ExtractSectionF(int startPage, int endPage)

Document newDocument = new Document();
string filePath = string.Empty;
string fileName = string.Empty;

//loop through all the pages
foreach (Page pdfPage in m_pdfDocument.Pages)
if ((pdfPage.Number >= startPage) && (pdfPage.Number <= endPage))

fileName = string.Format("\{0}.pdf", GetUniqueKey());

// need to generate a unique file name
filePath = WorkingDirectory + fileName;


return filePath;


In the above case startPage = 3513, endPage = 3812, and pdfPage.Number = 3670. The error occurs adding the page to the newDocument.

So here is my question; should I be handling larger PDF files differently? Is there a better way to code this to handle memory more efficiently?

Any input is appreciated.

Hi there,

Thanks for your inquiry. You are using a quite older version. Please download and try latest version of Aspose.Pdf for .NET, hopefully it will resolve the issue as we have made a lot of fixes and improvements/enhancement in later versions. If the issue exists then please share your sample code and document. We will test the scenario and will provide you information accordingly.

We are sorry for the inconvenience caused.

Best Regards,

P.S: You may request a 30 days temporary license to test issue without evaluation limitation.

This seems to have helped. I have operators running more in depth testing now. I didn’t realize I was on such an old version. Thank you!

Hi Aenders,

Please keep using the latest release and in the event of any further query, please feel free to contact.