Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed Nov 15, 2023 6:51 pm

When doc file contains an image, it fails to convert to PDF when running on linux.

Using Spire.Doc v11.11.0 on .net6

Running on Linux

Getting following error when running code => doc.SaveToStream(docxstream, FileFormat.PDF)

Code: Select all
{
  "errorType": "TypeInitializationException",
  "errorMessage": "The type initializer for 'Gdip' threw an exception.",
  "stackTrace": [
    "at System.Drawing.SafeNativeMethods.Gdip.GdipLoadImageFromDelegate_linux(StreamGetHeaderDelegate getHeader, StreamGetBytesDelegate getBytes, StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek, StreamCloseDelegate close, StreamSizeDelegate size, IntPtr& image)",
    "at System.Drawing.Image.InitializeFromStream(Stream stream)",
    "at System.Drawing.Bitmap..ctor(Stream stream)",
    "at spr熕..ctor(Byte[] A_0)",
    "at spr愸.㮷()",
    "at spr愸.㬆(Stream A_0)",
    "at spr鬪.㬆()",
    "at spr鬪.〘()",
    "at spr鑀.⾢(spr関 A_0)",
    "at spr通.㭁(spr謈 A_0)",
    "at spr躸.㬆(spr謈 A_0)",
    "at spr蹽.㰭()",
    "at spr㿟.⎯()",
    "at spr㹽.↜(sprṉ A_0)",
    "at Spire.Doc.Document.㰭(Stream A_0, ToPdfParameterList A_1)",
    "at Spire.Doc.Document.㭁(Stream A_0)",
    "at Spire.Doc.Document.SaveToFile(Stream stream, FileFormat fileFormat)",
    "at Spire.Doc.Document.SaveToStream(Stream stream, FileFormat fileFormat)",
    "at WordToPdf.Services.WordToPDFConverter.Execute(Stream docxStream, Stream pdfOutStream, IEnumerable`1 mailMergeFields) in C:\\Dev\\WordToPdfLambda\\WordToPdf.Services\\WordToPDFConverter.cs:line 18",
    "at WordToPdf.Services.FunctionHandler.ExecuteAsync(FunctionInput input) in C:\\Dev\\WordToPdfLambda\\WordToPdf.Services\\FunctionHandler.cs:line 32",
    "at WordToPdf.Services.FunctionHandler.ExecuteAsync(FunctionInput input) in C:\\Dev\\WordToPdfLambda\\WordToPdf.Services\\FunctionHandler.cs:line 35",
    "at WordToPdfLambda.Function.FunctionHandler(FunctionInput input, ILambdaContext context) in C:\\Dev\\WordToPdfLambda\\src\\WordToPdfLambda\\Function.cs:line 33",
    "at lambda_method1(Closure , Stream , ILambdaContext , Stream )",
    "at Amazon.Lambda.RuntimeSupport.Bootstrap.UserCodeLoader.Invoke(Stream lambdaData, ILambdaContext lambdaContext, Stream outStream) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/UserCodeLoader.cs:line 145",
    "at Amazon.Lambda.RuntimeSupport.HandlerWrapper.<>c__DisplayClass8_0.<GetHandlerWrapper>b__0(InvocationRequest invocation) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/HandlerWrapper.cs:line 55",
    "at Amazon.Lambda.RuntimeSupport.LambdaBootstrap.InvokeOnceAsync(CancellationToken cancellationToken) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/LambdaBootstrap.cs:line 180"
  ],
  "cause": {
    "errorType": "PlatformNotSupportedException",
    "errorMessage": "System.Drawing.Common is not supported on non-Windows platforms. See https://aka.ms/systemdrawingnonwindows for more information.",
    "stackTrace": [
      "at System.Drawing.LibraryResolver.EnsureRegistered()",
      "at System.Drawing.SafeNativeMethods.Gdip..cctor()"
    ]
  }
}

hjorgensen
 
Posts: 1
Joined: Tue Nov 14, 2023 11:31 pm

Thu Nov 16, 2023 2:34 am

Hello,

Thanks for your inquiry.
The NET6 dlls of our Spire.Doc has the dependency System.Drawing.Common, which depends on Libgdiplus library. The windows system includes the Libgdiplus library by default, while the Linux don't include it. "The type initializer for 'Gdip' threw an exception" is caused by the absence of Libgdiplus on your Linux system.
Additionally, starting from .NET 6, System.Drawing.Common is no longer supported on non-Windows systems. To address the issue you encountered, our Spire.Doc provides the NetStandard dlls that uses SkiaSharp as a replacement for System.Drawing.Common. Please download the Spire.Doc Pack (hot fix) Version: 11.11.0from our website. After extracting the files, manually import the DLLs from the "netstandard2.0" folder into your project. 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,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.Doc