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

Free Support Forum - aspose.com

Aspose PDF Out of memory Exception with version 9.6.0.0

I’m getting out of memory exception with the attached code. We do have corporate license under

Inovalon Inc.

Process:-
We convert list of .PNG image to PDF using Aspose and then convert to a memorystream. While converting more than 150 .PNG images to memorystream we get out of memory exception.

Please let me know a better way or am i missing something.

Thanks
Ram

C# Code:

Stream myStream;
using (var outputStream = new MemoryStream())
{
using (Aspose.Pdf.Document doc = new Aspose.Pdf.Document())
{
foreach (var page in request.SelectedPages)
{
string filePath = DataCollectionDesktopDataAccess.GetWorkOrderImageFilePath(userId, page.WorkOrderId.Value, page.PageId);
if (File.Exists(filePath))
{
byte[] imageBytes = DataCollectionDesktopDataAccess.LoadOfflineWorkOrderImageFromDisk(userId, page.WorkOrderId.Value, page.PageId);
myStream = new MemoryStream(imageBytes);
AddPdfPage(doc, myStream);
//myStream.Close();
}
}
doc.Save(outputStream); // Get out of memory exception for more than 150 pages
myStream.Close();
}
request.PdfArray = outputStream.ToArray();
}
private void AddPdfPage(Aspose.Pdf.Document document, Stream stream)
{
// add a page to pages collection of document
Aspose.Pdf.Page pdfPage = document.Pages.Add();
using (Bitmap b = new Bitmap(stream))
{
// Set margins so image will fit, etc.
pdfPage.PageInfo.Margin.Bottom = 0;
pdfPage.PageInfo.Margin.Top = 0;
pdfPage.PageInfo.Margin.Left = 0;
pdfPage.PageInfo.Margin.Right = 0;
pdfPage.PageInfo.Width = b.Width;
pdfPage.PageInfo.Height = b.Height;
}
//Create an image object
Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();
//Add the image into paragraphs collection of the section
pdfPage.Paragraphs.Add(image1);
// set the image file stream
image1.ImageStream = stream;
}

Hi Ram,


Thanks for your inquiry. I am afraid I could not test your code exactly due to missing references. I will appreciate if you please share a sample console application to replicate the issue. However, I have tried your code after a bit amendment and unable to notice the issue.

Stream myStream=null;<o:p></o:p>

using (var outputStream = new MemoryStream())

{

using (Aspose.Pdf.Document doc = new Aspose.Pdf.Document())

{

for (int i=0;i<200;i++)

{

byte[] imageBytes = File.ReadAllBytes(@"E:/Data/chart.PNG"); ;

myStream = new MemoryStream(imageBytes);

AddPdfPage(doc, myStream);

// myStream.Close();

}

doc.Save(outputStream); // Get out of memory exception for more than 150 pages

// var outputPdffile = new FileStream("E:/data/outpuPdffile_stream.pdf", FileMode.Create, FileAccess.Write);

// outputStream.CopyTo(outputPdffile);

myStream.Close();

}

}

Please feel free to contact us for any further assistance.


Best Regards,

Hi,

Thanks for the quick reply. Appreciated!!!

I have attached my solution which gives out of memory exception. The only difference instead of File.ReadAllBytes we use our own decrypt method. In our case for less than 500 charts(pages) we get the exception.In our case each page is 700 to 1000Kb in size.
Let us know what’s the better way to avoid this out of memory exception.

Plz select a image with 1000Kb in size and run the app.

Thanks
Ram

Hi Ram,


Thanks for your feedback. I have managed to notice the reported out of memory exception when used image with >1000Kb for testing. So I have logged a ticket PDFNEWNET-39179 in our issue tracking system for further investigation and resolution. We will notify you as soon as it is resolved.

We are sorry for the inconvenience caused.

Best Regards,

Thanks again for quick reply.


If its possible, Let me know the turn around time and any work around available through Aspose Pdf?

We retrieve the images(png) stored as blob from db one by one as a memory stream and convert them into Pdf through Aspose software. If Aspose has a better way of doing this process please let us know? we are having a bit of time crunch on our side…

Thanks
Ram
Hi Ram,

Thanks for your feedback.

raminovalon:

If its possible, Let me know the turn around time and any work around available through Aspose Pdf?


We can not confirm you ETA at the moment as we recently noticed the issue. We will be in a good position to share a timeline after completion of the issue analysis. Moreover I am afraid I can not suggest you any workaround, you need to wait for the fix.

raminovalon:

We retrieve the images(png) stored as blob from db one by one as a memory stream and convert them into Pdf through Aspose software. If Aspose has a better way of doing this process please let us know? we are having a bit of time crunch on our side....


In reference to retrieving contents form database, I am afraid Aspose does not offer any feature for this. Customer need to read it using his own code and logic. You may google for a better/efficient approach for this.

Best Regards,