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

Free Support Forum - aspose.com

Converting excel to PDF to Jpeg throwing out of memory issue

Aspose.Total


converting excel to PDF to Jpeg throwing out of memory issue

Hi,


Thanks for the template file.

If I understand you correctly, you are using Aspose.Cells to convert to PDF and then use Aspose.PDF to convert PDF to Jpeg file format, is it correct?

I have evaluated your template Excel file which has about 100k pages in the second sheet and tested Excel to PDF conversion which would take lot of time to convert to PDF, lots of pages are blank as you may confirm this taking the print preview of the sheet(s) in MS Excel. For your information, converting so many pages to PDF would surely consume more resources and certain amount of memory. And, if you are successful to render the file with your resources, the output file would be of several hundreds of MB in size.

By the way, could you elaborate and share the sample code (runnable) to point which sample line of code (by which Aspose API) produces the exception, you may debug it on your end, so we could evaluate it further.

Thank you.




You are correct.

Below is the error STACK TRACE.
getting report: Out of memory. Hide
System.Exception: getting report: Out of memory. —> System.OutOfMemoryException: Out of memory. at System.Drawing.Graphics.CheckErrorStatus(Int32 status) at System.Drawing.Graphics.DrawImage(Image image, Int32 x, Int32 y, Int32 width, Int32 height) at …() at …(Stream , ) at Aspose.Pdf.Devices.JpegDevice.Process(Page page, Stream output) at Aspose.Pdf.Devices.PageDevice.Process(Page page, String outputFileName)

Hi,


The error seems to be related to Aspose.Pdf component, so I am moving this thread to Aspose.Total forum, so the respective team (Aspose.Pdf team) could look into it soon.


Thank you.


Hi Krishnat,


Thanks for your inquiry. We will appreciated it if you please share a console application or working sample code, so we will look into it and guide you accordingly.

We are sorry for the inconvenience caused.

Best Regards,
private IEnumerable CreatePreviewPDF(CreatePreviewImagesMediaAction action, int maxPreviewCount)
{
Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense(GetAsposeLicenseFilePath());

ImageDevice imageDevice;
switch (action.PreviewFormat)
{
case ImageFormat.Gif:
imageDevice = new GifDevice(new Resolution(action.Resolution));
break;

case ImageFormat.Jpg:
imageDevice = new JpegDevice(new Resolution(action.Resolution), 100);
break;

case ImageFormat.Png:
imageDevice = new PngDevice(new Resolution(action.Resolution));
break;

default:
throw new NotSupportedException("preview format not supported: " + action.PreviewFormat);
}
using (Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(action.Path))
{
for (int pageNumber = 1; pageNumber <= pdfDocument.Pages.Count && pageNumber <= maxPreviewCount; pageNumber++)
{
string fileName = App.GetTemporaryFile(action.PreviewFormatExtension);
imageDevice.Process(pdfDocument.Pages[pageNumber], fileName);
yield return new Preview(fileName, pageNumber) { ResizeToSystem = true };
}
}
}

Hi Krishnat,


Thanks for your feedback. I am afraid I am unable to render your shared excel file to PDF, process stalls for infinite time. I will appreciate it if you please share your source PDF document here, so we will test PDF to Image conversion scenario at our end and will let you know our findings.

Moreover, please note our forum supports attachment of a file upto 20MB, if file size of your source PDF is bigger than that then please share it via some free file sharing service, Dropbox, skydrive etc.

We are sorry for the inconvenience caused.

Best Regards,

Hi,

The correct exception is while rendering Excel to PDF.
I checked this using below sample code for the attached Excel file. What is the issue with the code?

Aspose.Cells.License license = new Aspose.Cells.License();
//license.SetLicense(GetAsposeLicenseFilePath());

string pdfFilePath = @“E:\CHECKASPOSEEXCEL\CHECKASPOSEEXCEL\CHECKASPOSEEXCEL\bin\OUTPUT\file2.pdf”;

Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(@“E:\CHECKASPOSEEXCEL\CHECKASPOSEEXCEL\CHECKASPOSEEXCEL\bin\INPUT\The Last Focus Order Guides 4 30.xlsx”);
wb.Save(pdfFilePath, Aspose.Cells.SaveFormat.Pdf);

Hi,

Any updates on this. can you please let me know what is wrong with the excel file.

Hi,


We did evaluate your template Excel file which has about approx. 100k pages in total so Excel to PDF conversion by Aspose.Cells would take a lot of time, more memory and resources. I found, lots of pages are actually blank with headers/footer text only as you may confirm this by taking the print preview of the second sheet in MS Excel manually. Furthermore, in between the blank pages, I found, there are some unnecessary value/ text placed in some cells which almost does span it even more than 16,000 columns in the sheet, this would consequently results in more than 90k pages in count. As you may think, rendering around 100k pages would surely take more and more memory and time and the output PDF file (if you could render it successfully) would be even more than 350MB in size.

To render your file with such a big big worksheet with unnecessary blank pages and unnecessary text/value in a few cells, you have to cope with it by specifying the printable area (based on your valid data only) for the second sheet especially. After re-setting the printable area, you can render to PDF efficiently and quickly, see the sample code that works fine and it renders to PDF very quickly.
e.g
Sample code:

Workbook wb = new Workbook(“e:\test2\The+Last+Focus+Order+Guides+4+30.xlsx”);



//Set the printable areas for the second sheet.
foreach (Worksheet sheet in wb.Worksheets)
{
if (sheet.Name == “Hospice Items”)
{

int maxRow = sheet.Cells.MaxDataRow;
int maxCol = 4;

if (maxCol > 0 && maxRow > 0)
{
Aspose.Cells.PageSetup pageSetup = sheet.PageSetup;
pageSetup.PrintArea = “A1:” + CellsHelper.CellIndexToName(maxRow, maxCol);
}
}
}

wb.Save(“e:\test2\out1.pdf”);


Let us know if you still have any issue.

Thank you.