[Aspose.Pdf and Words for dotnet] PlatformNotSupportedException for PDF to Image and Word to Image Conversion

Hi Team,
We have hosted Aspose.Pdf and Aspose.Words on linux server and when trying to convert PDF or Word file to Image, We are getting this exception:

System.AggregateException: One or more errors occurred. (The type initializer for 'Gdip' threw an exception.)\n ---> System.TypeInitializationException: The type initializer for 'Gdip' threw an exception.\n ---> System.PlatformNotSupportedException: System.Drawing.Common is not supported on non-Windows platforms. See https://aka.ms/systemdrawingnonwindows for more information.\n

Is there any workaround for this? How can we support image operations on linux hosted environments?

@kgaidhani

Instead of Aspose.PDF for .NET, please try using Aspose.Pdf.Drawing (latest version) as it does not contain dependency of System.Drawing. In case issue still persists, please let us know.

1 Like

Thanks for you reply asad, I have a scenario where I am doing following:
ImageDevice device = new JpegDevice(page, resolution); device.Process(pdfDocument.Pages[pageNumber], imageStream);

Here in the device.Process method i am getting that exception. I am not able to follow which method would be the substitute for converting to image in Aspose.Pdf.Drawing, could you please help me with that?

Or is it the case that just by referencing this Aspose.Pdf.Drawing in the solution would work and i don’t necessarily have to make code change?

Thanks!

@kgaidhani

Aspose.PDF.Drawing has the same API as Aspose.PDF and JpegDevice.Process should be accessible. Furthermore, you also should install libgdiplus package in the Linux OS in order to get the API working correctly. In case you still notice any issues, please let us know.