Issue While Converting HTML to PDF on Linux Using Aspose Library - System.Drawing.Common

Hi Team -

We are using .net library. We are facing an issue while converting HTML to PDF using the Aspose library after deploying changes to Dev environment on Linux server. The same functionality works fine in local environment on Windows Server.

Below is the exception we are encountering:

StatusCode: 500 CorrelationId: jwfqcwmd Message: Internal Server Error. Exception: System.TypeInitializationException: The type initializer for ‘Gdip’ threw an exception. —> System.PlatformNotSupportedException: System.Drawing.Common is not supported on non-Windows platforms. See https://aka.ms/systemdrawingnonwindows for more information. at System.Drawing.SafeNativeMethods.Gdip…

@nitingautam

Summary

Your HTML → PDF conversion works on Windows but fails on Linux with

System.PlatformNotSupportedException: System.Drawing.Common is not supported on non‑Windows platforms

Aspose.PDF for .NET uses System.Drawing for some rendering operations (e.g., HTML layout, image handling). On Linux the classic GDI+ implementation is unavailable, so the call to Gdip throws the exception you are seeing.

You have two reliable ways to fix the problem:

  1. Upgrade to a recent Aspose.PDF for .NET version that no longer depends on System.Drawing (recommended).
  2. Provide a GDI+ implementation on the Linux host (alternative, only needed if you must stay on an older Aspose.PDF version).

Both approaches are explained in detail below.


:one: Upgrade to the latest Aspose.PDF for .NET (recommended)

Why this works

From v23.6 (and later) Aspose.PDF switched the HTML‑to‑PDF rendering engine to ImageSharp, which is fully cross‑platform and does not require System.Drawing.Common. The same code that you run on Windows will work on Linux without extra native libraries.

Steps

Step Action
1 Update the NuGet package(s) to the latest version. Example (CLI):
dotnet add package Aspose.Pdf --version 23.12
2 (Optional) Remove any explicit reference to System.Drawing.Common from your project file – it is no longer required for HTML‑to‑PDF.
3 Re‑build and redeploy the application to the Linux server.
4 Test the conversion again.

Sample code (no change needed for most scenarios)

using Aspose.Pdf;
using Aspose.Pdf.HtmlLoadOptions;

public void ConvertHtmlToPdf(string htmlPath, string pdfPath)
{
    // Load HTML
    HtmlLoadOptions loadOptions = new HtmlLoadOptions
    {
        // You can fine‑tune options here (e.g., page size, embed images, etc.)
    };

    using (Document pdfDoc = new Document(htmlPath, loadOptions))
    {
        // Save as PDF
        pdfDoc.Save(pdfPath);
    }
}

Note: If you were using any System.Drawing types (e.g., Bitmap, Graphics) directly in your own code, replace them with SixLabors.ImageSharp equivalents or remove them if they are not required for the conversion.

Documentation links


:two: Install a GDI+ implementation on Linux (if you cannot upgrade)

If you must keep an older Aspose.PDF version (e.g., due to other dependencies), you can supply the missing GDI+ APIs via libgdiplus. This makes System.Drawing.Common usable on Linux.

Prerequisites

OS Command
Ubuntu / Debian sudo apt-get update && sudo apt-get install -y libgdiplus libc6-dev
CentOS / RHEL sudo yum install -y libgdiplus
Alpine apk add --no-cache libgdiplus

After installation, create a symbolic link so that the .NET runtime can locate the library:
sudo ln -s libgdiplus.so /usr/lib/libgdiplus.so

Configure the .NET runtime (optional but recommended)

Add the following to your project’s runtime configuration (e.g., runtimeconfig.template.json) to explicitly enable System.Drawing on Linux:

{
  "runtimeOptions": {
    "configProperties": {
      "System.Drawing.EnableUnixSupport": true
    }
  }
}

Then rebuild the project.

Limitations

  • libgdiplus is a partial implementation of GDI+. Some advanced drawing features may behave differently or be unavailable.
  • Performance can be slower than the native ImageSharp‑based engine used in newer Aspose.PDF releases.

Documentation links


:three: Quick checklist for a clean deployment

  1. Upgrade to the latest Aspose.PDF for .NET (preferred).
  2. If staying on an older version, install libgdiplus and set System.Drawing.EnableUnixSupport = true.
  3. Ensure the Aspose.PDF license file is correctly located on the Linux server (typically App_Data or a path you set in code).
  4. Verify that the .NET runtime version on the server matches the version you built against (e.g., .NET 6/7).
  5. Test the conversion in a stand‑alone console app on the Linux box to isolate environment issues.

Next steps for you

  • Try the upgrade first – it resolves the issue with a single NuGet update and removes the platform dependency completely.
  • If you encounter any new error after the upgrade, please post the exact exception message and the version numbers of .NET and Aspose.Pdf you are using.
  • Should you need to stay on the older version, follow the Install libgdiplus steps and let us know if the exception persists.

We’re here to help!
If you need further assistance—such as detailed deployment scripts, Dockerfile snippets, or help migrating your custom System.Drawing code—just let us know.

Happy coding! :rocket:

Thank you for Reply

  1. We are using latest version of Aspose Nuget package i.e. 25.11.0.

  2. In runtimeconfig.template.json, we implemented “System.Drawing.EnableUnixSupport”: true.

  3. We installed the Prerequisites in Docker file also.

image.png (118.3 KB)

@nitingautam

Instead of Aspose.PDF for .NET, please install and use Aspose.Pdf.Drawing for .NET. It was released only to work in Linux like operating systems because it does not have dependency upon System.Drawing.Common. Please uninstall previous package and install the suggested one. In case you still face any issues, please let us know.

thank you, Ali, but we need PDF conversion from HTML - for which we still need Aspose.PDF - are you suggesting installing Drawing as well for drawing objects instead of using drawing objects from Aspose.PDF?