Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Wed Nov 15, 2023 6:42 pm

Hello,
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

mangood77
 
Posts: 1
Joined: Fri Apr 10, 2020 8:09 am

Thu Nov 16, 2023 10:03 am

Hello,

Thanks for your inquiry.
The NET6 dlls of our Spire.Pdf depend the System.Drawing.Common, please kindly note that starting from .NET 6, System.Drawing.Common is no longer be supported on non-Windows systems. To address the issue you encountered, our Spire.Pdf provides the NetStandard dlls that uses SkiaSharp as a replacement for System.Drawing.Common. Please download the FreeSpire.Pdf from our website, after unzipping the it, manually import the DLLs from the "netstandard2.0" folder into your project. as shown in the screenshot below:
2023-11-16 180056.png

Also, import the following external references through the NuGet Manager:
SkiaSharp >= 2.80.0
System.Buffers >= 4.5.1
System.Memory >= 4.5.5
Microsoft.Win32.Registry >= 4.5.0
System.Text.Encoding.CodePages >= 4.5.0
System.Security.Cryptography.Pkcs >= 4.5.0
System.Security.Cryptography.Xml >=4.5.0
System.Security.Permissions >= 4.5.0
HarfBuzzSharp >=2.6.1.5

Sincerely,
Ula
E-iceblue support team
User avatar

Ula.wang
 
Posts: 282
Joined: Mon Aug 07, 2023 1:38 am

Return to Spire.PDF