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

Complete Exception:
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.
at System.Drawing.LibraryResolver.EnsureRegistered()
at System.Drawing.SafeNativeMethods.Gdip.PlatformInitialize()
at System.Drawing.SafeNativeMethods.Gdip…cctor()

This happens when I start Aspose.Pdf.Devices.PngDevice.Process(Page page, Stream output)
to get an PNG output of a specific PDF page.

How can I do this unter Linux with code, which runs also under Windows?

@HauptlorenzAG

We already logged an issue to test Aspose.PDF functionality under .NET 6.0 in non-Windows environments as PDFNET-50918. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Can you say something about when this will be available (estimation is enough for me)?
I’m in the process of buying your component but I will need this.

@HauptlorenzAG

Hopefully, the Aspose.PDF beta version for this issue will be available by the end of November 2022. Please note that this ETA is not final at the moment. We will be sure to inform you once there is any update available on it.

That would be great if this happens in 2022!

I’ve read that 22.11.0 should have beta support for PDF on Linux (containers).
So’ve tested it, but it still throws an Exception while using PngDevice.Process() to extract single pages:

System.PlatformNotSupportedException: System.Drawing.Common is not supported on this platform.
at System.Drawing.Drawing2D.Matrix…ctor(Single m11, Single m12, Single m21, Single m22, Single dx, Single dy)
at #=zbl3SBT90TdOAO$oRLeX_Ss6xhQv9ZNRPwGQ8YEU=…ctor(Single #=z52V2DSo=, Single #=zEeG1QME=, Single #=zVAgQyeo=, Single #=zrygJJXU=, Single #=zO_5tCQA=, Single #=zKI9yMS0=)
at #=zS5SNRUbbtWTK6OAdX2NPHj0fe$42Gt$eSg==.#=zMlGezlk=(Single #=z52V2DSo=, Single #=zEeG1QME=, Single #=zVAgQyeo=, Single #=zrygJJXU=, Single #=zO_5tCQA=, Single #=zKI9yMS0=, #=z2SWwQqCeK640IC7bCsKpYEoWt5v8SSqG7g== #=zXEHgK7E=)
at #=zEo6E7BHUghkybt5AYcr40WE19jbqNjxeZsYcooe30ZpX.#=zofkBOjWUumTv(#=zVaDoWzSvQa$udhgm3bB3HwMReeeblTSNjw== #=z97RnNUE=, #=zH5ILmxrvcFdzxmPIPBwITygqF$hGwZZ_PkIc1NI= #=zpkZgZAKENnCq, #=zGqKMQgy2YbDer9110sPxTnE3RQnjNPK6Qg== #=zA1BRrwA=, Single #=zhDiAMQE3CJaD, Single #=zL3MCCMG01GQq, Boolean #=zDqVfVgAPXIoHksUulw==, Int32 #=zaeCcLuHQJEErxZgH9q1btAs=, Boolean #=zBY03Qs5qjYYq, Double& #=zK7dZ$yo=, Double& #=zySr6SeY=, #=zwZm3A5qREmsvk1pGWlmM9VuNDWLe6$4$bQ==& #=zwB5G0v4=)
at #=zEo6E7BHUghkybt5AYcr40WE19jbqNjxeZsYcooe30ZpX…ctor(#=zjkZS1CM6coW70JonQpFxVxrxg3e4 #=z2XFwSls=, #=zVaDoWzSvQa$udhgm3bB3HwMReeeblTSNjw== #=z97RnNUE=, #=zH5ILmxrvcFdzxmPIPBwITygqF$hGwZZ_PkIc1NI= #=zpkZgZAKENnCq)
at #=zPyAzPXxWVitoKseUIG0xwLDONA_iA7Jdy$KuZmg=.#=zgueSt11TFacv(#=zjkZS1CM6coW70JonQpFxVxrxg3e4 #=z2XFwSls=, #=zVaDoWzSvQa$udhgm3bB3HwMReeeblTSNjw== #=z97RnNUE=, #=zH5ILmxrvcFdzxmPIPBwITygqF$hGwZZ_PkIc1NI= #=zpkZgZAKENnCq)
at #=zNmsVZT4wg6kbjrIToJVnYv3canh3DMuQ4Ajx$LjFjjUo.#=zIqpyetQ=(#=zjkZS1CM6coW70JonQpFxVxrxg3e4 #=z2XFwSls=, #=zVaDoWzSvQa$udhgm3bB3HwMReeeblTSNjw== #=z97RnNUE=, #=zH5ILmxrvcFdzxmPIPBwITygqF$hGwZZ_PkIc1NI= #=zP9SjuMo=, #=zEo6E7BHUghkybt5AYcr40WE19jbqNjxeZsYcooe30ZpX& #=z9zUnJnA=)
at #=zZiXN9cK8btV785iE8KD2_9y$tzYl.#=zzBwO8Tc=(#=zEo6E7BHUghkybt5AYcr40WE19jbqNjxeZsYcooe30ZpX& #=z9zUnJnA=)
at #=zZiXN9cK8btV785iE8KD2_9y$tzYl.#=zzBwO8Tc=()
at Aspose.Pdf.Devices.ImageDevice.#=zzBwO8Tc=(Page #=z97RnNUE=)
at Aspose.Pdf.Devices.PngDevice.Process(Page page, Stream output)

@HauptlorenzAG

Unfortunately, this issue PDFNET-50918 has not resolved yet. We will be sure to inform you once there is an update available on it. We apologize for your inconvenience.

Can I see somewhere PDFNET-50918, so that I have not to ask every time?

@HauptlorenzAG

You can check the ticket status at the bottom of this forum thread. This ticket is logged under free support model where issues are resolved on a first come first serve basis. In case we have some updates while investigating and resolving the issue, we will also inform you in this forum thread.
image.png (2.8 KB)

1 Like

Hi Team,

Is this issue is relsoved, if yes can you guys share version for it. We have almost stuck on this after purchase of license as our infrastcure is linux containers or is there any other alternative to conevrt pdf to images apart from above solution which gives platform issue.

1 Like

@amolpwani,

Currently, there is a version for non-windows systems that do not rely on System.Drawing.

This is the Aspose.Pdf.Drawing.

You need to replace any reference to Aspose.Pdf for Aspose.Pdf.Drawing.

The latest version is: NuGet Gallery | Aspose.PDF.Drawing 23.3.1

Hi Team,

Thank you for your response, but this has solved platform issue but now getting another issue
**After using Aspose.Pdf.Drawing 23.3.1 version I am facing **
**Unhandled exception. System.Exception: No suitable system fonts found **
for
Aspose.Pdf.Devices.JpegDevice.Process(Page page, Stream output)

Please find my code snippet
using Aspose.Pdf.Devices;
using Aspose.Pdf.Text;
using Document = Aspose.Pdf.Document;

namespace PdfToImageConverter
{
    class Program
    {
        static void Main(string[] args)
        {
            string inputFile = "/app/input.pdf"; // Input PDF file path in the container
            string outputDir = "/app/output"; // Output directory path in the container

            using (Document pdfDocument = new Document(inputFile))
            {
                for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
                {
                    string outputFileName = Path.Combine(outputDir, $"page{pageCount}.png");

                    // Create the image device and set its resolution
                    //PngDevice pngDevice = new PngDevice(new Resolution(300));
                    JpegDevice jpegDevice = new JpegDevice(new Resolution(300));
                    string fontPath = "/usr/share/fonts/truetype/fonts-freefont-ttf/";
                    FontRepository.Sources.Add(new FolderFontSource(fontPath));

                    // Render the PDF page to the image device
                    using (FileStream outputStream = new FileStream(outputFileName, FileMode.Create))
                    {
                        jpegDevice.Process(pdfDocument.Pages[pageCount], outputStream);
                    }
                }
            }
        }
    }
}

image.png (8.6 KB)

@amolpwani,

Can you check that all your APIs are updated? In case you are using any other Aspose API

Do this problem only happends on document that use this font? Try with another one that does use this font

Can you actually find the dont using: var font = FontRepository.FindFont(“your font name”);? Check if the font is actually found.

Can you try installing the font on the system? if possible

In mcr.microsoft.com/dotnet/sdk:7.0 docker container it not finding fonts, we need to explitly install it using
RUN apt-get install -y --no-install-recommends fontconfig libfontconfig1 libxrender1 libxext6 libx11-6
&& echo “deb Index of /debian buster contrib” >> /etc/apt/sources.list
&& apt-get update
&& apt-get install -y --no-install-recommends fonts-noto fonts-dejavu fonts-freefont-ttf ttf-mscorefonts-installer
Then only it is able to run it cleanly, may be somewhere you should publish this.

@amolpwani,

Can you answer the 3 question I asked above please.

I need to know the answer of that in order to continue.

Can you check that all your APIs are updated? In case you are using any other Aspose API
- All APIs are updated

Do this problem only happends on document that use this font? Try with another one that does use this font
- This happens with almost all pdfs

Can you actually find the dont using: var font = FontRepository.FindFont(“your font name”);? Check if the font is actually found.
- It is finding font, but not sure hich font differet pdfs are using.

Can you try installing the font on the system? if possible
- This happens specifically, when try to run code in mcr.microsoft.com/dotnet/sdk:7.0 linux container or asp.net container

@amolpwani,

Can you do some code that prints all the Font Families in your system?

foreach (var family in systemFonts.Families)
{
    Console.WriteLine(family.Name);
}

Please check that the font you need is there.

I also would like a quick code snippet with a screenshot of the result of your code finding the font.