@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:
- Upgrade to a recent Aspose.PDF for .NET version that no longer depends on System.Drawing (recommended).
- 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.
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
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
Quick checklist for a clean deployment
- Upgrade to the latest Aspose.PDF for .NET (preferred).
- If staying on an older version, install libgdiplus and set
System.Drawing.EnableUnixSupport = true.
- Ensure the Aspose.PDF license file is correctly located on the Linux server (typically
App_Data or a path you set in code).
- Verify that the .NET runtime version on the server matches the version you built against (e.g., .NET 6/7).
- 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! 