Aspose.PDF System.Drawing.Common is not supported on non-Windows

Hi Team,
We are facing issue System.Drawing.Common is not supported on non-Windows platform.

Exception thrown: ‘System.TypeInitializationException’ in System.Drawing.Common.dll
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…cctor()
— End of inner exception stack trace —
at System.Drawing.SafeNativeMethods.Gdip.GdipCreateRegion(IntPtr& region)
at System.Drawing.Region…ctor()
at #=z_aL8VQXoO3CxT0v_SpaU2N0CmIyZ8T6vJg==.#=z$yDO1QI=(#=zBMAZdRIAZoLwjH2gzd41OySr9hAWlcl5EA== #=zDyBqjB4=)
at #=zEzv$z2zkfX1TDKM9kZy3yD8ErKOcYWnTJl933D8=.Clone()
at #=zxrj4KUg1CpEiA2m$Gh_VP6efsSEGXInKynen7y0=.#=zNfW65OI=()
at #=z2SWwQqCeK640IC7bCsKpYGQdE7vSxZG0XDH5nAs=.#=zNfW65OI=()
at #=zQQQfENZTaKIKlWaAVsTwb2EtORt6.#=zqCnlY9pR42fb()
at #=zQNQCREwZ98k001Xsugn$PZ5izZakQL6lOzUckeR98F$B.#=zqCnlY9pR42fb()
at #=zQNQCREwZ98k001Xsugn$PZ5izZakQL6lOzUckeR98F$B.#=zh0D1WJ0IZf5C()
at #=zQNQCREwZ98k001Xsugn$PZ5izZakQL6lOzUckeR98F$B.#=zStB5fBg=()
at #=zKXTBi68KtkGWk6EKjkT0wpFiKWkoBscxqC9fwy11Ge_w.#=zGuNZzb4=(#=zHwGJLkDeZXzorkLaivBnsrKvGb2M #=zo9B9Di8=, #=zNDa3OtYUjlyMhd2pwb9Ahmc2mRM2e3zqyg== #=zRUk5cvU=, #=z8E6sfPfruhOHxqT0VnXFWQVA1Gs_u0L_2QTsQjuaxEup #=zYgKbAXU=)
at Aspose.Pdf.Page.CalculateContentBBox()
at Aspose.Pdf.Page.#=zBTJFTgA=(Page #=zRUk5cvU=)
at Aspose.Pdf.Page.#=zuwi5qU2SzdlsBEHGPA==()
at Aspose.Pdf.Document.ProcessParagraphs()
at Aspose.Pdf.Document.#=z3PzDI1h0iwDy(Stream #=zaU7ngSo=, SaveOptions #=za6Jkedt4YB14)
at Aspose.Pdf.Document.#=ziWj61LPZf9YV(String #=zerzOOAW38Q8b)
at Aspose.Pdf.Document.Save(String outputFileName)

We are deploying our application in a Linux container.
The following line were added to the Dockerfile.

RUN apt-get update && apt-get install -y libgdiplus
RUN sed -i’.bak’ ‘s/$/ contrib/’ /etc/apt/sources.list
RUN apt-get update; apt-get install -y ttf-mscorefonts-installer fontconfig

@Jesuss
This occurs because from .Net 6 System.Drawing.Common is not supported on non-Windows platform (on Linux in particular).
Use the Aspose.Pdf.Drawing library (instead of Aspose.Pdf). This library uses Aspose.Drawing instead of System.Drawing.Common. Its main limitation is that api printing is not supported at the moment.

Would this be viable for html string to PDF generation?
Below is the code snippet.

using Aspose.Pdf;
Document doc = new Document();
Page page = doc.Pages.Add();
HtmlFragment htmlFragment = new HtmlFragment(htmlString);
page.Paragraphs.Add(htmlFragment);
doc.Save(pdfFileNamePath);

@Jesuss
Yes it looks right

Hi Sergei,

I’m not unable to locate any of the class in Aspose.Pdf.Drawing used in the code snippet.
Currently, I have Aspose.Total installed.

Please advise on how to using Aspose.Pdf.Drawing instead of Aspose.Pdf

@Jesuss
You should use the nuget package (library) Aspose.Pdf.Drawing instead of Aspose.Pdf. Everything else (all code, all calls) remains the same.

@sergei.shibanov
If I replace the the Aspose.Pdf nuget package with Aspose.Pdf.Drawing, getting error like there is not Pages.Add() method.
Even there is no Pages class.

@Jesuss is your problem fixed by replacing the package.

@Santosh_Singh
I took the code for the .Net 6 project

var htmlString = "string";
var doc = new Document();
var page = doc.Pages.Add();
var htmlFragment = new HtmlFragment(htmlString);
page.Paragraphs.Add(htmlFragment);
doc.Save(myDir + "withDrawing.pdf"); 

and connected Aspose.Pdf.Drawing 23.8 - it worked for me.
Maybe you included Aspose.Drawing instead of Aspose.Pdf.Drawing ?

Thanks @sergei.shibanov
my issue is resolved using your solution

@Santosh_Singh
Glad it worked out for you. Thanks for your feedback.