I'm currently testing the FreeSpire PDF for .NET library. I'm using it within a .NET 6 application, and everything works fine on Windows. However, I need to run it in a Docker container on Linux. I'm aware that SkiaSharp is theoretically used instead of System.Drawing, but I'm encountering an issue with two lines of code:
- Code: Select all
PdfPageBase newPage = doc.Pages.Add(page.Size, new PdfMargins(0));
doc is an object of type Spire.Pdf.PdfDocument
page is a Spire.Pdf.PdfPageBase object
now my error on this line:
- Code: Select all
Unhandled exception. System.TypeInitializationException: The type initializer for 'Gdip' threw an exception.
---> System.PlatformNotSupportedException: System.Drawing.Common is not supported on non-Windows platforms. See https://aka.ms/systemdrawingnonwindows for more information.
at System.Drawing.LibraryResolver.EnsureRegistered()
at System.Drawing.SafeNativeMethods.Gdip.PlatformInitialize()
at System.Drawing.SafeNativeMethods.Gdip..cctor()
--- End of inner exception stack trace ---
at System.Drawing.SafeNativeMethods.Gdip.GdipCreateMatrix(IntPtr& matrix)
at System.Drawing.Drawing2D.Matrix..ctor()
at sprᡓ..ctor()
at Spire.Pdf.Graphics.PdfCanvas.ᜆ()
at Spire.Pdf.Graphics.PdfCanvas.Save()
at Spire.Pdf.PdfPageLayer.ᜀ(PdfPageBase A_0)
at Spire.Pdf.PdfPageLayer.get_Graphics()
at Spire.Pdf.PdfPageBase.get_Canvas()
at Spire.Pdf.Widget.PdfPageCollection.ᜁ(PdfSection A_0, Int32 A_1, PdfPageBase A_2)
at Spire.Pdf.Widget.PdfPageCollection.Insert(Int32 index, PdfNewPage page, PdfPageSettings settings, Boolean existsPage)
at Spire.Pdf.Widget.PdfPageCollection.Insert(Int32 index, SizeF size, PdfMargins margins, PdfPageRotateAngle rotation, PdfPageOrientation orientation, Boolean existsPage)
at Program.<Main>$(String[] args) in /app/Program.cs:line 110
Additionally,
- Code: Select all
newPage.Canvas.DrawTemplate(page.CreateTemplate(), new PointF(xleft, xtop));
page and newPage are objects of type Spire.Pdf.PdfPageBase but it use PointF from System.Drawing
I think i can't use System.Drawing
I'm using SkiaSharp now in my project and I've solved System.Drawing problems in many other places but not here
I will be grateful for any suggestions.
Regards