System.Drawing.Common dependency on linux environments

We are facing an issue when trying to convert a PostScript file to PDF in containerized Linux environments (.NET 9).

When calling the SaveAsPdf method on a PsDocument, the following exception is thrown:

pgsql

CopyEdit

System.PlatformNotSupportedException: System.Drawing.Common is not supported on this platform.
    at System.Drawing.Brush..ctor()
    at System.Drawing.SolidBrush..ctor(Color color)
    at #=zaAHci2YRwy2gIgZy6g==..ctor()
    at #=z7vlhUC9RmhwKmDRWLI$DPZgluIcwWDyp$g==..ctor(Stream #=zfCGqL6g=)
    at Aspose.Page.EPS.PsDocument.SaveAsPdf(Stream pdfStream, PdfSaveOptions options)

The Aspose libraries used in the project as a whole are as follows:

xml

CopyEdit

<PackageReference Include="Aspose.CAD" Version="25.3.0" />
<PackageReference Include="Aspose.Cells" Version="25.3.0" />
<PackageReference Include="Aspose.Diagram" Version="25.2.0" />
<PackageReference Include="Aspose.Email" Version="25.2.0" />
<PackageReference Include="Aspose.HTML" Version="25.3.0" />
<PackageReference Include="Aspose.Imaging" Version="25.3.0" />
<PackageReference Include="Aspose.Page" Version="25.2.0" />
<PackageReference Include="Aspose.PDF.Drawing" Version="25.2.0" />
<PackageReference Include="Aspose.PSD" Version="25.2.0" />
<PackageReference Include="Aspose.Slides.NET6.CrossPlatform" Version="25.3.0" />
<PackageReference Include="Aspose.Words" Version="25.3.0" />

The code snippet that is throwing the exception is as follows:

csharp

CopyEdit

using (FileStream fs = new FileStream(OriginalFilePath, FileMode.Open, FileAccess.Read))
{
    PsDocument document = new PsDocument(fs);

    using (FileStream pdfStream = new FileStream(ConvertedFilePath, FileMode.Create, FileAccess.Write))
    {
        document.SaveAsPdf(pdfStream, options);
    }

    document = null;
}

Do you have any insights on how to resolve this issue?

@rpassos2

The issue you are encountering with the System.PlatformNotSupportedException when trying to convert a PostScript file to PDF in a Linux environment is related to the System.Drawing.Common library, which is not supported on Linux platforms. This is a known limitation when using certain Aspose libraries that rely on System.Drawing.

To resolve this issue, you can consider the following approaches:

  1. Use a Different Library: If your application can be modified, consider using libraries that do not depend on System.Drawing.Common. For example, you might explore using Aspose libraries that are designed to work natively on Linux without relying on System.Drawing.

  2. Check for Updates: Ensure that you are using the latest version of the Aspose libraries. Sometimes, newer versions may have addressed compatibility issues or provided alternative methods for handling graphics.

  3. Run on Windows: If feasible, you could run your application in a Windows environment where System.Drawing.Common is fully supported. This is not always ideal, especially in containerized environments, but it is a workaround.

  4. Monitor Issue Tracking: There is an ongoing investigation regarding this issue, and it may be beneficial to keep an eye on updates from Aspose regarding the resolution of this limitation.

For further assistance, you can refer to the following example that demonstrates how to convert a PostScript file to PDF using Aspose.Page, which may help you adapt your code accordingly:

using Aspose.Page.EPS;
using Aspose.Page.EPS.Device;
using System.IO;

public class PostScriptToPdf
{
    public static void Convert(string originalFilePath, string convertedFilePath)
    {
        using (FileStream fs = new FileStream(originalFilePath, FileMode.Open, FileAccess.Read))
        {
            PsDocument document = new PsDocument(fs);
            PdfSaveOptions options = new PdfSaveOptions(true); // Suppress errors if needed

            using (FileStream pdfStream = new FileStream(convertedFilePath, FileMode.Create, FileAccess.Write))
            {
                document.SaveAsPdf(pdfStream, options);
            }
        }
    }
}

This code snippet initializes a PsDocument and saves it as a PDF, while also allowing for error suppression if needed. Make sure to adapt the paths and options as per your requirements.

If you have further questions or need additional assistance, feel free to ask!

The provided snippet still results in the same exception

@rpassos2

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PAGENET-756

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@rpassos2
Hello,
for Linux, please, use Aspose.Page.Drawing package instead of Aspose.Page.