3

I am running a Dotnet core app (3.1) on a Mac (Catalina) and I’m trying to add an image to a PDF using Aspose PDF with this tutorial: https://docs.aspose.com/pdf/net/manipulate-images/.

I get an error when trying to add the 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

Doing my research, this appears to be related to needing the libgdiplus library. I installed this with brew install mono-libgdiplus but I am still getting this error.

Sample Project that can replicate the issue: https://github.com/duyn9uyen/aspose-add-image-to-pdf.

Aspose.Pdf: Version=“20.3.0”.

Can someone help?

duyn9uyen
  • 9,585
  • 12
  • 43
  • 54
  • We have responded to your similar inquiry over Aspose.PDF forum. You may please follow up there. This is Asad Ali and I work as Developer Evangelist at Aspose Pty Ltd. – Asad Ali Sep 08 '20 at 22:26
  • No answer from the forum? https://forum.aspose.com/t/gdip-threw-an-exception-with-dotnet-core-3-x-app-on-mac-osx/218193/2 – duyn9uyen Sep 12 '20 at 19:57

1 Answers1

11
  1. Need to install libgdiplus. https://learn.microsoft.com/en-us/dotnet/core/install/macos

    brew update 
    brew install mono-libgdiplus
    
  2. Need to install CoreCompat.System.Drawing from https://github.com/CoreCompat/CoreCompatdotnet. Add this package reference, runtime.osx.10.10-x64.CoreCompat.System.Drawing --version 5.8.64 in your .csproj file.

    <PackageReference Include="runtime.osx.10.10-x64.CoreCompat.System.Drawing" Version="5.8.64" />
    
duyn9uyen
  • 9,585
  • 12
  • 43
  • 54