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

Free Support Forum - aspose.com

System.OutOfMemoryException' in Aspose.Words.dll

Hi to all!
I am getting ‘System.OutOfMemoryException’ in Aspose.Words.dll while i try conwert big ( 128mb) TXT file to PDF.

The code is :

protected override PdfRenderResponse RenderToPdf(PdfRenderRequest request)
{
    byte[] content;

    using (var reader = new StreamReader(request.Stream))
    using (var outputStream = new MemoryStream())
    {
        var text = reader.ReadToEnd();
        var builder = new DocumentBuilder();
        builder.Write(text);

        var saveOptions = new global::Aspose.Words.Saving.PdfSaveOptions()
        {
            Compliance = global::Aspose.Words.Saving.PdfCompliance.Pdf17,
        };

        builder.Document.Save(outputStream, saveOptions);

        content = outputStream.ToArray();
    }

    var returnValue = new PdfRenderResponse
    {
        Content = content,
    };

    return returnValue;
}

The file is 128MB.zip (410.2 KB) (zipped).

the exception getting thrown here:

builder.Document.Save(outputStream, saveOptions);

i will appreciate any suggestions for solving this problem.

Thank you !

Log:

2022-02-04 14:22:20,155 ERROR [32] - Exception occurred during the handling of PdfRenderRequest for file: '341.txt': 'System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at ?  ..ctor(Int32 )
   at    ..ctor(Inline ,  ?  , String , ?   )
   at ?  .(Inline , String , Boolean )
   at    . ()
   at    .()
   at ?  .()
   at Aspose.Words.Document.UpdatePageLayout()
   at    .( ?  , ??  )
   at    .?    ( ?  )
   at ?? .??   ( ?  )
   at Aspose.Words.Document.( ?  )
   at Aspose.Words.Document.(Stream , String , SaveOptions )
   at Aspose.Words.Document.Save(Stream stream, SaveOptions saveOptions)

@shubna Thank you for reporting this problem to us. But I am afraid the document is simply too large for rendering. MS Word also cannot convert your document to PDF it hangs for a while and then shows the following error:

Which is not surprising, your document contains 2097154 lines (paragraphs in Aspose.Words DOM), one page contains about 46 lines. In your sample document one paragraph fits one line on the page so the final document will contain about 45k pages.

I would recommend you to split such abnormally huge documents into parts.

1 Like

Thank you very much @alexey.noskov!!!