How to Work with PDF Files in .Net Core on Docker and Linux

IronPDF now fully supports Docker, Linux and MacOS deployments and debugging. This allows true cross platform portability of our C# PDF library. 
 Now we can Create, Edit and Read PDFs on Linux, Mac and Docker with IronPDF


When we deploy to Linux and Docker we have to ensure that the instance has the relevant packages installed to support PDF rendering. These packages are often not present in minimalist Linux builds, Docker VMS - but are easy to add.

Linux & Docker - Automatic Setup

Adding the following code to your project. Setting LinuxAndDockerDependenciesAutoConfig true will automatically attempt to install all dependancies for IronPDF to run on Linux. The first html-to-pdf operation may longer than usual packages are installed.

IronPdf.Installation.LinuxAndDockerDependenciesAutoConfig = true;
IronPdf.Installation.LinuxAndDockerDependenciesAutoConfig = True
VB   C#

This works on Debian and Ubuntu

Manual Installation for Docker Linux Images

First we recommend this excellent article on setting up Docker debugging and integration with Visual Studio projects.

Cleaning Up First

Amend your Docker File

Adding these RUN ["apt-get"] lines to your Dockerfile. Generally at the top, normally second line just after the first docker image is defined

# FROM AS base
# After first docker image is defined - install all these dependancies

RUN ["apt-get", "update"]
RUN ["apt-get", "-y", "install", "libgdiplus"]
RUN ["apt-get", "-y", "install", "xvfb", "libfontconfig", "wkhtmltopdf"]
RUN ["apt-get", "-y", "install", "libc6-dev"]
RUN ["apt-get", "-y", "install", "openssl"]
RUN ["apt-get", "-y", "install", "libssl1.0-dev"]

Alternative Docker IronPDF Setup Solution in C# Code

If you find Docker files frustrating (see above); instead of amending the Docker file we can programmatically require the Linux / Docker dependancies for the PDF library.

Add the following code to your solution and run it only once per dployment - this will take a few minutes the next time you run IronPDF. Watch the Visual Studio "Output" window for progress.

 if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux))
        Debug.Write("Attempting to automatically install Linux / Docker dependencies.  This may take some time on your first run on this machine.");

            var p1 = System.Diagnostics.Process.Start("apt-get", "update");
            var p2 = System.Diagnostics.Process.Start("apt-get", " install -y libgdiplus");
            var p3 = System.Diagnostics.Process.Start("apt-get", "install -y   xvfb libfontconfig wkhtmltopdf");
            var p4 = System.Diagnostics.Process.Start("apt-get", " install -y   libc6-dev");
            var p5 = System.Diagnostics.Process.Start("apt-get", " install -y   openssl");
            var p6 = System.Diagnostics.Process.Start("apt-get", " install -y   libssl1.0-dev");

            Debug.Write("Linux / Docker dependency installation success");

            Debug.Write("Linux / Docker dependency installation failure");
If System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux) Then
		Debug.Write("Attempting to automatically install Linux / Docker dependencies.  This may take some time on your first run on this machine.")

			Dim p1 = System.Diagnostics.Process.Start("apt-get", "update")
			Dim p2 = System.Diagnostics.Process.Start("apt-get", " install -y libgdiplus")
			Dim p3 = System.Diagnostics.Process.Start("apt-get", "install -y   xvfb libfontconfig wkhtmltopdf")
			Dim p4 = System.Diagnostics.Process.Start("apt-get", " install -y   libc6-dev")
			Dim p5 = System.Diagnostics.Process.Start("apt-get", " install -y   openssl")
			Dim p6 = System.Diagnostics.Process.Start("apt-get", " install -y   libssl1.0-dev")

			Debug.Write("Linux / Docker dependency installation success")

			Debug.Write("Linux / Docker dependency installation failure")
		End Try
End If
VB   C#

Manual Installation for Linux Machines

We just need to make sure the dependencies are there. Its as easy as

apt-get update
apt-get install -y libgdiplus xvfb libfontconfig wkhtmltopdf libc6-dev openssl libssl1.0-dev

Current support is tested on Ubuntu 12+, Debian 8+ and recent CentOS

MacOS Support

We have found that iron PDF works 'out of the box' on MacOS operating systems.
Whwer any of teh following packages missing, they could be installed using HomeBrew.

  • libgdiplus
  • xvfb
  • libfontconfig
  • wkhtmltopdf
  • libc6-dev
  • openssl
  • libssl1.0-dev