Image compression options are not working in non-windows server

We are using Aspose License and trying to reduce PDF document size by using optimization options. All optimization options working fine except images compress options.
Its working fine in local environment which is windows. We deployed same code to Linux server(Ubuntu). Its returning Not supported image type error while compressing PDF document.
Please suggest if we have a way to resolve this issue.

Error:
System.NotImplementedException: Not supported image type\n at Aspose.Pdf.XImage.#=zIiigXgQ=(ImageFormat #=zuWsmbks=, Int32 #=ze7ihkeI=)\n
at Aspose.Pdf.XImage.#=zixZh8fE=(ImageFormat #=zdcO71xg=)\n at #=ztO64Avni3qq7rQ5p4eNhCJTKDcmtYrkMjNDPhyw=.#=zy5r$HLAiA0h7c$dU4g==(OperatorCollection #=zUMFrcIQ=, Resources #=zucCm36Y=)\n
at #=ztO64Avni3qq7rQ5p4eNhCJTKDcmtYrkMjNDPhyw=.#=zFTd3ulQ=(Document #=zSnDpKwc=)\n
at #=z_xr9QCFPcaX$gihWzRQWC2Q_$bkx.#=zFTd3ulQ=(OptimizationOptions #=zUQgZ6SA=)\n
at Aspose.Pdf.Document.OptimizeResources(OptimizationOptions strategy)\n

Code:

var optimizationOptions = new Aspose.Pdf.Optimization.OptimizationOptions();
optimizationOptions.RemoveUnusedObjects = true;
optimizationOptions.RemoveUnusedStreams = true;
optimizationOptions.AllowReusePageContent = true;
optimizationOptions.LinkDuplcateStreams = true;
optimizationOptions.CompressObjects = true;
optimizationOptions.UnembedFonts = true;
optimizationOptions.ImageCompressionOptions.CompressImages = true;
optimizationOptions.ImageCompressionOptions.ImageQuality = 30;
optimizationOptions.ImageCompressionOptions.ResizeImages = true;
optimizationOptions.ImageCompressionOptions.Version = Aspose.Pdf.Optimization.ImageCompressionVersion.Fast;
optimizationOptions.ImageCompressionOptions.MaxResolution = 72;
optimizationOptions.ImageCompressionOptions.Encoding = ImageEncoding.Flate;
pdfDocument.OptimizeResources(optimizationOptions);

@SOMESWARABODDALA

It seems that you are encountering a NotSupportedImageType error when trying to compress images in a PDF document on a Linux server using Aspose.PDF. This issue may arise due to differences in how image formats are handled between Windows and Linux environments.

Here are a few suggestions to help you resolve this issue:

  1. Check Image Formats: Ensure that the images in your PDF are in a format that is supported by Aspose.PDF on Linux. Common formats like JPEG and PNG should work, but if you are using less common formats, consider converting them to a supported format before processing.

  2. Update Aspose.PDF Library: Make sure you are using the latest version of the Aspose.PDF library. There may have been updates or bug fixes that address compatibility issues with image formats on Linux.

  3. Test with Different Image Compression Settings: You can try adjusting the image compression settings in your code. For example, you might want to experiment with different values for ImageQuality or Encoding. Here’s a modified version of your code snippet that you can try:

    var optimizationOptions = new Aspose.Pdf.Optimization.OptimizationOptions();
    optimizationOptions.RemoveUnusedObjects = true;
    optimizationOptions.RemoveUnusedStreams = true;
    optimizationOptions.AllowReusePageContent = true;
    optimizationOptions.LinkDuplcateStreams = true;
    optimizationOptions.CompressObjects = true;
    optimizationOptions.UnembedFonts = true;
    
    // Adjust image compression settings
    optimizationOptions.ImageCompressionOptions.CompressImages = true;
    optimizationOptions.ImageCompressionOptions.ImageQuality = 50; // Try a higher quality
    optimizationOptions.ImageCompressionOptions.ResizeImages = true;
    optimizationOptions.ImageCompressionOptions.Version = Aspose.Pdf.Optimization.ImageCompressionVersion.Fast;
    optimizationOptions.ImageCompressionOptions.MaxResolution = 150; // Increase resolution if needed
    optimizationOptions.ImageCompressionOptions.Encoding = ImageEncoding.Jpeg; // Change encoding to JPEG
    
    pdfDocument.OptimizeResources(optimizationOptions);
    
  4. Log Detailed Errors: If the issue persists, consider logging more detailed error messages or stack traces to help identify the specific image type that is causing the problem.

  5. Consult Aspose Support: If none of the above solutions work, you may want to reach out to Aspose support directly with details about the image types you are using and the specific environment setup. They may have more insights or specific fixes for your issue.

By following these steps, you should be able to troubleshoot and potentially resolve the image compression issue on your Linux server.

Sources:
[1]: OptimizePDFFileSize.java