Aspose.word 生成 word文档时 内容中包含图片, linux服务器生成异常

一. 问题描述

  1. 使用netcore开发 (netcore3.1+NuGet引用的Aspose.Words 20.7)
  2. word内容中包含图片时, 在window10系统下运行正常, 部署在linux(Linux 3.10.0-957.el7.x86_64 x86_64
    )系统下生成word异常.

二. 生成word代码 示例

Aspose.Words.Document doc = new Aspose.Words.Document();
Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);

// 方法1 插入图片
builder.InsertImage(HttpContext.MapPath("/data/image.jpg", true), 400, 600);

//方法2 插入图片
builder5.InsertHtml("");

doc.Save(HttpContext.MapPath("/test.docx", true));

三. 错误日志
Unhandled exception. System.TypeInitializationException: The type initializer for ‘SkiaSharp.SKObject’ threw an exception.
—> System.TypeInitializationException: The type initializer for ‘SkiaSharp.SKColorSpace’ threw an exception.
—> System.DllNotFoundException: Unable to load shared library ‘libSkiaSharp’ or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibSkiaSharp: cannot open shared object file: No such file or directory
at SkiaSharp.SkiaApi.sk_colorspace_new_srgb()
at SkiaSharp.SKColorSpace…cctor()
— End of inner exception stack trace —
at SkiaSharp.SKColorSpace.EnsureStaticInstanceAreInitialized()
at SkiaSharp.SKObject…cctor()
— End of inner exception stack trace —
at SkiaSharp.SKObject.DeregisterHandle(IntPtr handle, SKObject instance)
at SkiaSharp.SKObject.set_Handle(IntPtr value)
at SkiaSharp.SKNativeObject.Dispose(Boolean disposing)
at SkiaSharp.SKObject.Dispose(Boolean disposing)
at SkiaSharp.SKBitmap.Dispose(Boolean disposing)
at SkiaSharp.SKNativeObject.Finalize()

@eastnet,

如果打算在Linux环境中使用Aspose.Words for .NET Standard,则应引用以下附加的NuGet程序包,以使其正确处理图形:

SkiaSharp.NativeAssets.Linux: 适用于Ubuntu(它也应可在大多数基于Debian的Linux发行版上使用)

要么

Goelze.SkiaSharp.NativeAssets.AlpineLinux 适用于Alpine Linux。 希望这可以帮助。

1 Like

非常感谢, 在netget中引用了 [SkiaSharp.NativeAssets.Linux] 后,linux服务器上word内容中包含图片可以正常生成了.

@eastnet,

感谢您的反馈意见。 很高兴您能够最终解决此问题。 如有任何其他疑问,请随时告诉我们。