Free Support Forum - aspose.com

Save PDF document into stream using C# with Aspose.PDF - out of memory exception

This code used to work previously. Recently, we upgraded to version 20.1.00.

Here is the code:
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(Path.Combine(Server.MapPath(@"~/Templates/" + pdfFileName)));

                        Page page = pdfDocument.Pages.Add();

                        TextFragment tableDescription = new TextFragment(ConfigurationManager.AppSettings["paaPDFTableText"])
                        {
                            Position = new Position(0, 0),
                            HorizontalAlignment = HorizontalAlignment.Center
                        };

                        page.Paragraphs.Add(tableDescription);

                            pdfStream = new MemoryStream();

                        pdfDocument.Save(pdfStream, SaveFormat.Pdf);

The last line gives the OutOfMemoryException. If I remove page.Paragraphs.Add(tableDescription);, this does not happen. Please advise.

@dpreznik,

Can you please share source file so that we may further investigate to help you out. Also please try to use Aspose.PDF latest version 20.2 on your end and if there is still an issue than please share requested files.

Upgrading does not help. Here is the source:

       static void Main(string[] args)
    {
        Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(@"F:\Projects\AsposeTestCs\SomeDocument.pdf");

        Page page = pdfDocument.Pages.Add();

        TextFragment tableDescription = new TextFragment("Some text that should be displayed")
        {
            Position = new Position(0, 0),
            HorizontalAlignment = HorizontalAlignment.Center
        };

        page.Paragraphs.Add(tableDescription); // This causes the trouble

        MemoryStream pdfStream = new MemoryStream();

        pdfDocument.Save(pdfStream, SaveFormat.Pdf); // Exception happens here

    }

@dpreznik,

I like to inform that you have shared source code with us. Can you please share source PDF with us for further investigation.

I just used a completely empty pdf. But I still attached it for you. SomeDocument.pdf (6.3 KB)

@dpreznik,

I have observed the issue that you have mentioned and have logged it as PDFNET-47765 in our issue tracking system. We will further look into details of the issue and keep you posted with the status of its correction. Please be patient and spare us little time.

We are sorry for the inconvenience.