设定PDF错误:Mac OSX上的Dotnet Core 3.x应用程序'Gdip'引发异常

问题描述

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

尝试添加imagestream时出现错误

”无效的图片流(“ Gdip”的类型初始值设定项 例外。”。

let session = URLSession(configuration: .default,delegate: delegate,delegateQueue: delegateQueue)

进行研究时,这似乎与需要 libgdiplus 库有关。我使用var logoFile = "logo.jpg"; FileStream imagestream = new FileStream(logoFile,FileMode.Open,FileAccess.Read); page.Resources.Images.Add(imagestream); //Error on this line 安装了该文件,但仍然收到此错误

可以复制问题的示例项目: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。在您的。runtime.osx.10.10-x64.CoreCompat.System.Drawing --version 5.8.64文件中添加此软件包引用csproj

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