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

Free Support Forum - aspose.com

Memory usage of the OptimizeResources too important

Hello,

In order to lighten the weight of PDFs in our database, we want to use Aspose.Pdf optimization.
We use Aspose.PDF .NET.
However, during our tests, we observed very high memory consumption, around 35MB of memory per MB of PDF in 64bit mode. Multiplied by 5 if used in a 32bit context (Sample : 5Mo pdf uses 900MB of memory in a 32 bit context !!! It’s hot!)

Technical constraints force us to use a 32 bit application, which is a concern for us. We therefore plan to go through another tool in 64bit, but the memory consumption remains high, is this normal?

Code C# with this pdf : https://inter-static.skywatcher.com/upfiles/en_download_caty01461862245.pdf (6.9MB => Memory usage : 250MB)

using Aspose.Pdf;
using Aspose.Pdf.Optimization;
using System;

namespace TestAsposePdfOptimisation
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Optimisation PDF !");
            
            const String fileName = "C:\\SI\\en_download_caty01461862245.pdf";
            const String fileNameOpti = "C:\\SI\\en_download_caty01461862245_opti.pdf";
            const String asposeLicence = "S:\\partage-dev\\Composants\\Aspose.Total.NET.lic";

            Aspose.Pdf.License license = new Aspose.Pdf.License();
            license.SetLicense(asposeLicence);

            var optiOptions = new OptimizationOptions();
            optiOptions.RemoveUnusedObjects = true;
            optiOptions.RemoveUnusedStreams = true;
            optiOptions.LinkDuplcateStreams = true;
            optiOptions.AllowReusePageContent = true;
            
            var imgCompressionOptions = optiOptions.ImageCompressionOptions;
            
            imgCompressionOptions.CompressImages = true;
            imgCompressionOptions.ImageQuality = 50;
            imgCompressionOptions.ResizeImages = true;
            imgCompressionOptions.MaxResolution = 150;

            Console.WriteLine("Chargement pdf...");
            var pdfDocument = new Aspose.Pdf.Document(fileName);
            Console.WriteLine("Avant optimisation...");
            pdfDocument.OptimizeResources(optiOptions);
            Console.WriteLine("Apres optimisation...");
            pdfDocument.Save(fileNameOpti);
            Console.WriteLine("Fin optimisation PDF !");
            Console.WriteLine(".");
        }
    }
}

@tonyryu

Can you please make sure that you are using 22.1 version of the API. If issue still persists, please share complete environment details i.e. OS Name and Version, .NET Framework Version, RAM Size, etc. along with a screenshot of memory consumption. We will investigate the issue accordingly and share our feedback with you.

The version of API is 22.1. (net4.0_ClientProfile)
Windows 10
The test application is a .NET framework 4.5 console application with 2 debug configuration (32bit/64bit) in VisualStrudio 2019.

image.png (4.8 KB)

The new code test

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestPdfOptimize
{
    class Program
    {
        static void Main(string[] args)
        {

            const String fileName = "C:\\SI\\190304_Original.pdf";
            const String fileNameOpti = "C:\\SI\\190304_Original.pdf";
            const String asposeLicence = "S:\\partage-dev\\Composants\\Aspose.Total.NET.lic";

            Aspose.Pdf.License license = new Aspose.Pdf.License();
            license.SetLicense(asposeLicence);

            Aspose.Pdf.Optimization.OptimizationOptions optiOptions = new Aspose.Pdf.Optimization.OptimizationOptions();
            optiOptions.RemoveUnusedObjects = true;
            optiOptions.RemoveUnusedStreams = true;
            optiOptions.LinkDuplcateStreams = true;
            optiOptions.AllowReusePageContent = true;

            var imgCompressionOptions = optiOptions.ImageCompressionOptions;

            imgCompressionOptions.CompressImages = true;
            imgCompressionOptions.ImageQuality = 50;
            imgCompressionOptions.ResizeImages = true;
            imgCompressionOptions.MaxResolution = 150;

            Console.WriteLine("Chargement pdf...");
            Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(fileName);
            Console.WriteLine("Avant optimisation...");
            pdfDocument.OptimizeResources(optiOptions);
            Console.WriteLine("Apres optimisation...");
            pdfDocument.Save(fileNameOpti);
            Console.WriteLine("Fin optimisation PDF !");
            Console.WriteLine(".");

        }
    }
}

This file 190304_Original.pdf (4.5MB) contains personal data. But it helps to understand the problem :

@tonyryu

We have logged an investigation ticket as PDFNET-51285 in our issue tracking system to further analyze this case. We will look into its details and keep you posted with the status of ticket resolution. Please be patient and spare us some time.

We are sorry for the inconvenience.