Out of Memory exception with PDF.Document while converting large number of images into PDF

Hi,



We are getting Out of memory exception while converting large number of images into single PDF document.

We are using Aspose.Pdf.Document object and we are getting this error when we are doing save pdf using Save method.

Aspose PDF component version that we are using is 11.5.0

Source code used is attached.

Can you please check this issue and let us know the details ?

Hi Saravanan,


Thanks for your inquiry. I have tested the scenario with 200 image files and unable to notice the reported issue. We will appreciate it if you please share some more details about the issue, for example number of image files, size and image format. So we will try to replicate the issue at our end and will provide you information accordingly.

We are sorry for the inconvenience caused.

Best Regards,

Hi Tilal,

Thanks for the details.
Please find below the details requested.
Number of Image Files : More than 120
Image Size : Some files have 1MB
Image Format : JPEG and sometimes TIFF.
Please check and let us know.

Thanks.

Hi Saravanan,


Thanks for sharing additional information. I am trying to replicate the issue and will update you my findings soon.

Best Regards,

Hi Tilal,

Do we have any update on the issue ?
This issue is creating much problems in our production. So it would be good if we have any suggestions to resolve this issue.

Thanks.

Hi Saravanan,


Thanks for your patience. I have tested the Image to PDF conversion with 196 images of different sizes and formats, but I am unable to notice any memory exception. However I have noticed that memory consumption touched 1GB for some moments. I am using Aspose.Pdf for .NET 11.6.0 on Windows 7 64 bit and 8GB RAM. Please share your environment details, so we will further look into the issue and provide you information accordingly.

We are sorry for the inconvenience caused.

Best Regards,

I downloaded latest version of PDF 11.6v and my system configuration is Windows 7 64 bit and RAM is 8GB. Still I am getting the Out of memory issue. Upto 150MB PDF file is Generating. If it cross 150MB PDF file size it gives this error.



Also How to compress the PDF file size. for 50MB Images it generates 160MB PDF file size. We want Compress file size PDF.



I have attached one Zip file of Image. Please copy of that image into 50 files and run this code in your sample application.



I tried about 39 files which contains 60MB and try to generate the PDF with Below Code. I have attached the Screen shot of Files and Error Screen shot.



private void BuildPDFDocument(string pdfpath)

{

string[] FileList = null;

FileList = Directory.GetFiles(pdfpath, “.”);



try

{

Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document();



foreach (string filename in FileList)

{

Aspose.Pdf.Page pdfPage = pdfDocument.Pages.Add();

pdfPage.PageInfo.Margin.Bottom = 0;

pdfPage.PageInfo.Margin.Top = 0;

pdfPage.PageInfo.Margin.Left = 0;

pdfPage.PageInfo.Margin.Right = 0;



// Create an image object

Aspose.Pdf.Image pdfImage = new Aspose.Pdf.Image();



// Add the image into paragraphs collection of the section

pdfPage.Paragraphs.Add(pdfImage);



pdfImage.File = filename;

}



pdfDocument.Save(pdfpath + “\” + “Output” + “.pdf”);

pdfDocument.FreeMemory();

pdfDocument.Dispose();

pdfDocument = null;

}

catch (Exception ex)

{

throw new Exception(ex.Message);

}

}



Please provide the solution as soon. We have Production issue for this. Customer is asking. It stop the Production. Please help us soon.

Hi Saravanan,

Thanks for sharing your source image document. You may use OptimizeResources object to optimize the size of PDF document. Please check following documentation link for the details.

Furthermore, I have tested your shared code with 50 copies of shared image and unable to notice any exception. You may please share a sample console project, it will help us for further investigation.

string[] FileList = null;
FileList = Directory.GetFiles(myDir, "*.*");

Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document();

foreach (string filename in FileList)
{
    Aspose.Pdf.Page pdfPage = pdfDocument.Pages.Add();
    pdfPage.PageInfo.Margin.Bottom = 0;
    pdfPage.PageInfo.Margin.Top = 0;
    pdfPage.PageInfo.Margin.Left = 0;
    pdfPage.PageInfo.Margin.Right = 0;

    // Create an image object
    Aspose.Pdf.Image pdfImage = new Aspose.Pdf.Image();
    // Add the image into paragraphs collection of the section
    pdfPage.Paragraphs.Add(pdfImage);
    pdfImage.File = filename;
}

pdfDocument.ProcessParagraphs();

// Optimize the file size by removing unused objects
pdfDocument.OptimizeResources(new Document.OptimizationOptions()
{
    LinkDuplcateStreams = true,
    RemoveUnusedObjects = true,
    RemoveUnusedStreams = true,
    CompressImages = true,
    ImageQuality = 70
});

pdfDocument.Save(myDir + "Output.pdf");

We are sorry for the inconvenience caused.

Best Regards,