Could not generate PDF: System.OutOfMemoryException: Out of memory.
We are currently experiencing a System.OutOfMemoryException from the following code:
public void Build(ExternalReportPdf externalReportPdf)
{
using (var ms = new MemoryStream(externalReportPdf.SpotfirePdfBytes))
{
var externalPdfReport = new Aspose.Pdf.Document(ms);
if (externalPdfReport.Pages.Count > 0)
{
foreach (var page in externalPdfReport.Pages)
{
var rect = page.GetPageRect(true);
if (rect.Width > rect.Height)
{
_builder.CurrentParagraph.ParentSection.PageSetup.Orientation = Orientation.Landscape;
}
else
{
_builder.CurrentParagraph.ParentSection.PageSetup.Orientation = Orientation.Portrait;
}
using (var imageStream = new MemoryStream())
{
var resolution = new Aspose.Pdf.Devices.Resolution(300);
var jpegDevice = new Aspose.Pdf.Devices.JpegDevice(resolution, 100);
jpegDevice.Process(page, imageStream);
_builder.InsertImage(imageStream);
}
}
}
}
}
It throws on line 49 (marked in red). This only happens while running inside a Linux container. Running the same code on Windows works perfectly. The exception is preceded by the following warnings:
** (process:1): WARNING **: Path conversion requested 28958208 bytes (3264 x 2218). Maximum size is 8388608 bytes.
** (process:1): WARNING **: Path conversion requested 28958208 bytes (3264 x 2218). Maximum size is 8388608 bytes.
** (process:1): WARNING **: Path conversion requested 28958208 bytes (3264 x 2218). Maximum size is 8388608 bytes.
** (process:1): WARNING **: Path conversion requested 28958208 bytes (3264 x 2218). Maximum size is 8388608 bytes.
If we reduce the resolution from 300 to 150, the code executes fine on both Windows and Linux, but 150 is not enough for us.
The exact same issue has previously been reported by other Aspose customers, but no resolution is provided:
What we are trying to accomplish with the above code, is to convert a PDF page into an image, then insert each image into an Aspose.Words document using the DocumentBuilder class.
Let me also add that the container running the above code, do have enough physical resources. It has been configured with 4GB RAM, and it is only consuming about 600MB when the System.OutOfMemoryException occurs.