Aspose PDF error: ‘Gdip’ threw an exception with Dotnet Core 3.x app on Mac OSX

Aspose PDF error: ‘Gdip’ threw an exception with Dotnet Core 3.x app on Mac OSX

我是 运行 Mac (Catalina) 上的 Dotnet 核心应用程序 (3.1),我正在尝试通过本教程使用 Aspose PDF 将图像添加到 PDF:https://docs.aspose.com/pdf/net/manipulate-images/.

我在尝试添加 imageStream 时遇到错误。

"Invalid image stream (The type initializer for ‘Gdip’ threw an exception.)’.

var logoFile = "logo.jpg";
FileStream imageStream = new FileStream(logoFile, FileMode.Open, FileAccess.Read);
page.Resources.Images.Add(imageStream); //Error on this line

根据我的研究,这似乎与需要 libgdiplus 库有关。我用 brew install mono-libgdiplus 安装了它,但我仍然收到此错误。

可以重现问题的示例项目:https://github.com/duyn9uyen/aspose-add-image-to-pdf

Aspose.Pdf:版本=“20.3.0”。

有人可以帮忙吗?

  1. 需要安装libgdiplushttps://docs.microsoft.com/en-us/dotnet/core/install/macos

    brew update 
    brew install mono-libgdiplus
    
  2. 需要从 https://github.com/CoreCompat/CoreCompatdotnet 安装 CoreCompat.System.Drawing。在您的 .csproj 文件中添加此包参考 runtime.osx.10.10-x64.CoreCompat.System.Drawing --version 5.8.64

    <PackageReference Include="runtime.osx.10.10-x64.CoreCompat.System.Drawing" Version="5.8.64" />