Not supported image type error with Aspose.Pdf.RgbToDeviceGrayConversionStrategy.Convert

The requirement is to convert a pdf from color mode to black and white mode using Aspose.Pdf.RgbToDeviceGrayConversionStrategy.
The code snippet is as follows:

Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(filePath);
Aspose.Pdf.RgbToDeviceGrayConversionStrategy strategy = new Aspose.Pdf.RgbToDeviceGrayConversionStrategy();
for (int idxPage = 1; idxPage <= pdfDocument.Pages.Count; idxPage++)
{
    Page page = pdfDocument.Pages[idxPage];
    strategy.Convert(page);
}
pdfDocument.Save(filePath);

The code is working fine on local machine (Windows 11) where as the same code is not working when it is deployed to DEV environment (Linux machine).
Aspose.PDF version is 24.10.0
Error:

Not supported image type :    at Aspose.Pdf.XImage.#=zGn2HLJI=(ImageFormat #=zaS9IhBw=, Int32 #=zsdjWnvw=)
   at Aspose.Pdf.XImage.Save(Stream stream, ImageFormat format, Int32 resolution)
   at Aspose.Pdf.XImage.Save(Stream stream, ImageFormat format)
   at Aspose.Pdf.XImage.#=zV2lyCe4w2zn3SadIcA==()
   at #=z1l0_3PVI69xJvjgE$9s6gRHh5Ab40j57p1Oerx6BxtD_Yv$hsZ$_hGjy_ugG.#=z357MfTlPz1NY(XImageCollection #=z0G1CxhU=)
   at #=z1l0_3PVI69xJvjgE$9s6gRHh5Ab40j57p1Oerx6BxtD_Yv$hsZ$_hGjy_ugG.#=zJ_ytZmJo3vam(Resources #=zAPZXAiU=)
   at #=z1l0_3PVI69xJvjgE$9s6gRHh5Ab40j57p1Oerx6BxtD_Yv$hsZ$_hGjy_ugG.#=zuCNbsd4=(Page #=zsm9BCvY=)
   at Aspose.Pdf.RgbToDeviceGrayConversionStrategy.Convert(Page page)

@gpaspunuri

The error you are encountering, “Not supported image type,” when using the Aspose.Pdf.RgbToDeviceGrayConversionStrategy.Convert method on a Linux environment, may be due to differences in how image formats are handled between Windows and Linux. Here are some steps you can take to troubleshoot and potentially resolve the issue:

  1. Check Image Formats: Ensure that the images in your PDF are in a format that is supported by Aspose.PDF on Linux. Sometimes, certain image formats may not be supported or may require additional libraries on Linux.

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

  3. Test with Different PDFs: Try using a different PDF file that contains simpler images or fewer complex elements to see if the issue persists. This can help determine if the problem is specific to the content of the original PDF.

  4. Logging and Debugging: Implement logging to capture more detailed error messages or stack traces. This can provide insights into which specific image type is causing the issue.

  5. Environment Dependencies: Ensure that all necessary dependencies and libraries required by Aspose.PDF are installed on the Linux machine. Sometimes, missing libraries can lead to unexpected behavior.

  6. Sample Code: You can refer to the following sample code for converting a PDF from RGB to grayscale, which is similar to what you are trying to achieve:

    using Aspose.Pdf;
    
    // Load source PDF file
    Document document = new Document("input.pdf");
    RgbToDeviceGrayConversionStrategy strategy = new RgbToDeviceGrayConversionStrategy();
    
    for (int idxPage = 1; idxPage <= document.Pages.Count; idxPage++)
    {
        Page page = document.Pages[idxPage];
        strategy.Convert(page);
    }
    
    // Save resultant file
    document.Save("output.pdf");
    

If the issue persists after trying these steps, consider reaching out to Aspose support for further assistance, providing them with details about the images in your PDF and the specific environment setup.

Sources:
[1]: ConvertFromRGBToGrayscale.cs

@gpaspunuri

Currently, to work in Nix systems, you should use the Aspose.Pdf.Drawing library. This is a version of the library that uses Aspose.Drawing as a graphical backend.
Please try it and write if the problem persists.

Could not find any required classes for converting the color pdf in black and white mode in Aspose.Pdf.Drawing library. Please advise what might be applied in this scenario.

@gpaspunuri

You only need to change the library you use.
From Aspose.Pdf to Aspose.Pdf.Drawing.
The code itself, the license remain the same (I checked your code just in case).