简体   繁体   中英

PDFsharp document outofmemory exception

I have a PDF document created using PDFsharp. This pdf document has 1000 pages. I am trying to save this 1000 pages PDF document into memory stream. It gives out of memory exception while storing the document in stream. Can anyone help? Here is the code:

       var pdf = createPDFSharpDocument(); // some logic that makes the pdfsharp document.
        var stream = new MemoryStream();
        pdf.Save(stream, false);
       //some logic to use the stream that is generated

This question is a duplicate: https://stackoverflow.com/a/33609157/162529

Short answer: PDFsharp keeps everything in memory. Do not add too many PDF files in one round.

Make sure your program runs in 64 bit mode to make use of all the memory.

To reduce the memory footprint, add a few PDF files, save the stream, close it, re-open it, add a few PDF files and so forth.
And don't forget to close the PDF files you are importing from.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM