Using libgdiplus with IronOCR: Setup Guide

.NET Core requires libgdiplus to use the Microsoft System.Drawing.Common NuGet package. If it is not found on macOS or Linux, you may experience this exception:

  • Unhandled exception. System.DllNotFoundException: Could not find or load the native library from any name: [ libgdiplus, libgdiplus.so ]
  • If you see System.TypeInitializationException: The type initializer for 'Gdip' threw an exception, then please read our System.Drawing.Common in NET6 guide instead.

Linux

Ubuntu, Debian

To install the required libraries on Ubuntu or Debian, run the following command:

# Update package lists and install necessary libraries
sudo apt-get update && sudo apt-get install -y apt-utils libgdiplus libc6-dev
# Update package lists and install necessary libraries
sudo apt-get update && sudo apt-get install -y apt-utils libgdiplus libc6-dev
SHELL

Docker

Add the following line to your Dockerfile to ensure the necessary libraries are included in your Docker image:

# Update package lists and install necessary libraries in Docker container
RUN apt-get update && apt-get install -y apt-utils libgdiplus libc6-dev

macOS

If you encounter the following exception on macOS:

Unhandled exception. System.DllNotFoundException: Could not find or load the native library from any name: [ libgdiplus, libgdiplus.dylib ]

You can resolve this by:

# Update Homebrew and install mono-libgdiplus
brew update && brew install mono-libgdiplus
# Update Homebrew and install mono-libgdiplus
brew update && brew install mono-libgdiplus
SHELL