Unable to Compress file

We are trying to compress the pdf document using “Site OEM” trial license but we are getting below exception.
Could you please help on this, this is a blocker for us to proceed to go for paid license.

Language used: c#

2024-08-21T13:54:33.398986738Z Failed Compressed document: System.NotImplementedException: Not supported image type
2024-08-21T13:54:33.399021438Z at Aspose.Pdf.XImage.#=zIiigXgQ=(ImageFormat #=zuWsmbks=, Int32 #=ze7ihkeI=)
2024-08-21T13:54:33.399027038Z at Aspose.Pdf.XImage.#=zixZh8fE=(ImageFormat #=zdcO71xg=)
2024-08-21T13:54:33.399032438Z at #=ztO64Avni3qq7rQ5p4eNhCJTKDcmtYrkMjNDPhyw=.#=zy5r$HLAiA0h7c$dU4g==(OperatorCollection #=zUMFrcIQ=, Resources #=zucCm36Y=)
2024-08-21T13:54:33.399036838Z at #=ztO64Avni3qq7rQ5p4eNhCJTKDcmtYrkMjNDPhyw=.#=zFTd3ulQ=(Document #=zSnDpKwc=)
2024-08-21T13:54:33.399041238Z at #=z_xr9QCFPcaX$gihWzRQWC2Q_$bkx.#=zFTd3ulQ=(OptimizationOptions #=zUQgZ6SA=)
2024-08-21T13:54:33.399045538Z at Aspose.Pdf.Document.OptimizeResources(OptimizationOptions strategy)
2024-08-21T13:54:33.399050039Z at document_processing_service.Services.AsposeDocumentRenderer.CompressPdf(Byte[] inputBytes) in /src/document-processing-service/Services/AsposeDocumentRenderer.cs:line 426
2024-08-21T13:54:33.399054439Z Error compressing 400 page document.pdf: Unable to compressed document: System.NotImplementedException: Not supported image type
2024-08-21T13:54:33.399079539Z at Aspose.Pdf.XImage.#=zIiigXgQ=(ImageFormat #=zuWsmbks=, Int32 #=ze7ihkeI=)
2024-08-21T13:54:33.399086939Z at Aspose.Pdf.XImage.#=zixZh8fE=(ImageFormat #=zdcO71xg=)
2024-08-21T13:54:33.399092639Z at #=ztO64Avni3qq7rQ5p4eNhCJTKDcmtYrkMjNDPhyw=.#=zy5r$HLAiA0h7c$dU4g==(OperatorCollection #=zUMFrcIQ=, Resources #=zucCm36Y=)
2024-08-21T13:54:33.399096839Z at #=ztO64Avni3qq7rQ5p4eNhCJTKDcmtYrkMjNDPhyw=.#=zFTd3ulQ=(Document #=zSnDpKwc=)
2024-08-21T13:54:33.399101139Z at #=z_xr9QCFPcaX$gihWzRQWC2Q_$bkx.#=zFTd3ulQ=(OptimizationOptions #=zUQgZ6SA=)
2024-08-21T13:54:33.399105239Z at Aspose.Pdf.Document.OptimizeResources(OptimizationOptions strategy)
2024-08-21T13:54:33.399109239Z at document_processing_service.Services.AsposeDocumentRenderer.CompressPdf(Byte[] inputBytes) in /src/document-processing-service/Services/AsposeDocumentRenderer.cs:line 426
2024-08-21T13:54:33.399947447Z <3>Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1] An unhandled exception has occurred while executing the request. System.InvalidOperationException: Unable to compressed document: System.NotImplementedException: Not supported image type at Aspose.Pdf.XImage.#=zIiigXgQ=(ImageFormat #=zuWsmbks=, Int32 #=ze7ihkeI=) at Aspose.Pdf.XImage.#=zixZh8fE=(ImageFormat #=zdcO71xg=) at

@pkumar1826

It seems that you are encountering a System.NotImplementedException related to unsupported image types while trying to compress a PDF document using Aspose.PDF. This error typically occurs when the PDF contains images in a format that is not supported by the library for compression.

To resolve this issue, you can follow these steps:

  1. Check Image Formats: Ensure that the images in your PDF are in a supported format. Aspose.PDF supports common formats like JPEG, PNG, and BMP. If your PDF contains images in unsupported formats, consider converting them to a supported format before compression.

  2. Use Optimization Options: When compressing the PDF, you can specify optimization options that include image compression settings. Here’s a sample code snippet that demonstrates how to set up the optimization options for compressing images:

    using System;
    using Aspose.Pdf;
    using Aspose.Pdf.Optimization;
    
    class Program
    {
        static void Main()
        {
            // Load the PDF document
            Document pdfDocument = new Document("path/to/your/document.pdf");
    
            // Create optimization options
            OptimizationOptions optimizationOptions = new OptimizationOptions
            {
                LinkDuplcateStreams = true,
                RemoveUnusedObjects = true,
                RemoveUnusedStreams = true,
                ImageCompressionOptions = 
                {
                    CompressImages = true,
                    ImageQuality = 10 // Adjust quality as needed
                }
            };
    
            // Optimize the PDF document
            pdfDocument.OptimizeResources(optimizationOptions);
    
            // Save the optimized document
            pdfDocument.Save("path/to/your/optimized_document.pdf");
            Console.WriteLine("PDF document optimized successfully.");
        }
    }
    
  3. Flate Decode Compression: If you are specifically looking to use Flate Decode compression for images, ensure that you set the appropriate image filter type. This can help in reducing the file size while maintaining image quality.

  4. Review Documentation: For more detailed information on optimizing PDF files and handling images, you can refer to the Aspose documentation on optimizing PDF files, which provides insights into various techniques and options available for image compression.

If the issue persists after checking the image formats and applying the optimization options, consider reaching out to Aspose support for further assistance, as they may provide insights specific to your document’s content.

Sources:
[1]: Optimize, Compress or Reduce PDF Size in C# - Aspose Documentation
[2]: Flate Decode Compression | Aspose.PDF for .NET API Reference

Code we are trying to execute.

image.png (19.0 KB)

But when I try the same code in local environment, its working

@pkumar1826

Have you deployed your application on some non-Windows server? Have you tried using Aspose.Pdf.Drawing instead of Aspose.PDF for .NET? Please share complete information of the environment where you are facing this exception so that we can further proceed accordingly.