wkhtmltopdf migration

DinkToPdf: Unable to load shared library 'libwkhtmltox.so' — the cause and the fix

Your .NET program prints invoices or reports with DinkToPdf. It worked on your machine. In the container, it dies on the first PDF:

Marqius

Two illustrated invoice proofs aligned with a brass rule on a green desk
text
Unhandled exception. System.DllNotFoundException:
Unable to load shared library '/app/libwkhtmltox.so' or one of its dependencies.
In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable

What the message means, in plain words

DinkToPdf does not make PDFs itself. It loads a second file, libwkhtmltox.so, and that file does the work. That file is not part of DinkToPdf, and it is not part of .NET. It must be on the machine before the first PDF.

The runtime could not load the file. It may be missing, outside the library search path, or missing a system library it needs. If the file is present, run ldd /app/libwkhtmltox.so inside your Linux image and look for a dependency marked not found.

Why it appears in Docker and on new systems

  • The file only exists for the systems its makers built it for. The archived project published separate packages for specific distributions and CPUs, including Debian 12 and Ubuntu 22.04.
  • Alpine images need a different build (musl) than Debian images.
  • ARM machines — Apple Silicon, AWS Graviton, the ARM CI runners — need their own build. The error is common on ARM EC2 instances for exactly this reason.
  • Multi-stage Docker builds often copy the app but not the native file.

The fix: put the file into the image

On a Debian-based image, install the wkhtmltox package that matches your base. For mcr.microsoft.com/dotnet/aspnet:8.0 (Debian 12, bookworm):

dockerfile
RUN apt-get update && \
    apt-get install -y --no-install-recommends wget ca-certificates && \
    wget -q https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-3/wkhtmltox_0.12.6.1-3.bookworm_amd64.deb && \
    apt-get install -y --no-install-recommends ./wkhtmltox_0.12.6.1-3.bookworm_amd64.deb && \
    rm wkhtmltox_0.12.6.1-3.bookworm_amd64.deb

Three rules that decide whether this works:

  1. Match the base. Bookworm base → bookworm file. Bullseye → bullseye. Ubuntu 22.04 → jammy.
  2. Match the CPU. _amd64 on x64, _arm64 on ARM.
  3. Alpine is different. It needs a musl build; the Debian .deb will not load there.

The related error: System.BadImageFormatException

If you see 0x8007000B instead, the file was found but does not match the CPU: a 64-bit program loading a 32-bit file, or x64 loading an ARM file. The fix is the same idea — install the build that matches — and one more check: publish your app for the right runtime, for example dotnet publish -r linux-x64.

The deeper problem, and the way out

The file you are installing is from a project that was archived in January 2023. The upstream release includes separate Debian Bookworm and Ubuntu Jammy packages. Every fix above is a way to keep using it.

Update, 24 November 2026. We make Marqius.DinkToPdf: DinkToPdf's own API — every class, method and setting, compared line by line with the original on every build — with no libwkhtmltox at all. One reference and the errors above cannot happen:

xml
<PackageReference Include="Marqius.DinkToPdf" Version="0.12.15" />

The full guide, from your first PDF to Docker: wkhtmltopdf for .NET

Sources

Reader questions

Is DllNotFoundException the same as BadImageFormatException?

No. "Unable to load shared library" means the runtime could not load the file or one of its dependencies. "Bad image" (0x8007000B) means the file is there but built for a different CPU. Both are fixed by installing the right build.

Why did it work on my Windows machine?

Windows DinkToPdf setups usually carry wkhtmltox.dll next to the app already. The container starts empty, so the Linux file is simply absent.

What does it cost?

There are two licences. The Community licence is free: for personal projects, for teaching and learning, and for open-source projects, including their CI test runs and documentation builds. The commercial licence is for businesses.

Who makes it?

Marqius is commercial software from Simple AI LLC. It is independent of the wkhtmltopdf project and of DinkToPdf.