Compatibility of System.Drawing package in NET 6.0 and future NET 7.0

Product: PDFTron.NET.x64 (Nuget Package)

Product Version: 9.3.0

Please give a brief summary of your issue:
We found that when using PDFTron in our current linux machines after upgrading to NET6 has ended in a problem related to the System.Drawing library which is used from the PDFTron functionality used to extract PDF pages.

Please describe your issue and provide steps to reproduce it:
When using the pdftron library in a NET6 proyect throws an error that says:

System.TypeInitializationException : The type initializer for ‘Gdip’ threw an exception.
---- System.PlatformNotSupportedException : System.Drawing.Common is not supported on non-Windows platforms. See Breaking change: System.Drawing.Common only supported on Windows - .NET | Microsoft Learn for more information.

This issue seems to be related to the breaking change that microsoft did in this version of .NET.

Currently we were able to bypass this error by enabling the System.Drawing.EnableUnixSupport, but this will not be an option in NET 7. We will like to know if there is any plan on updating the library to keep this functionalities on future versions.

To be more precise the error happens when we try to get the “Bitmap” with PDFDraw from a Page.

using (Bitmap bitmap = draw.GetBitmap(page))

Hi Adria,

We are unable to reproduce this using Ubuntu20 (WSL2), .NET6, and PDFNet 9.4

Could you please try updating to the latest 9.4 version and see if that fixes the issue?

Does that mean that the PDFNet 9.4 doesn’t have any dependency with the System.Drawing library? If that’s not the case, how is the proper way to get the images from a page? Since Microsoft say that in Net7 this library will not have support in other systems different than windows due to the use of libgdiplus external dependency.


Tried with version 9.4, and the dependency still exists, if you try to compile the project, at the moment you try to save the image bitmap of the page, the compiler already warns you that the call to “bitmap.Save” is only available on windows.

Update 2:

If you want an example of this, create a project in Net6 that can target any platform and use the example of your docs: PDFTron Systems Inc. | Documentation
(Exactly same code). You will see that the compiler warns you with the code CA1416

We will like to know if there is any plan on updating the library to keep this functionalities on future versions.

We do not rely on System.Drawing.Common, all rendering is done by our SDK (since GDI doesn’t actually support PDF rendering, missing features).

The APIs like PDFDraw.GetBitmap are just convenience API’s. If Microsoft removes support for them then you would need to use our other API’s, like PDFDraw.Export.

In that case, there is any method to obtain the result image bytes without the need of creating a file in disk? In the c# SDK (.NET 9.4.0) the only method i see available is the export with the “filename” parameter as input (with 3 overloads).