DinkToPdf: Native library not loaded on Linux

Hi I’m having some serious issues with this package. I added the package to my project and copied the native .so file to the root of my ASP.NET Core project. Now when I start the application and try to convert HTML to PDF I get the following error:

(Exception from HRESULT: 0x8007007E)) ---> System.DllNotFoundException: Unable to load DLL 'libwkhtmltox': The specified module could not be found.

I’ve tried setting up LD_LIBRARY_PATH to my app folder. I even copied the .so file to /usr/lib but it doesn’t work at all.

Any ideas what to do here?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 28 (5 by maintainers)

Most upvoted comments

@fernandovictorTI, I believe the problem is that the second stage of your build (runtime) is not running the below command again, so libwkhtmltox and it’s dependencies are left in the first stage (build).

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        zlib1g \
        fontconfig \
        libfreetype6 \
        libx11-6 \
        libxext6 \
        libxrender1 \
    && curl -o /usr/lib/libwkhtmltox.so \
        --location \
        https://github.com/rdvojmoc/DinkToPdf/raw/v1.0.8/v0.12.4/64%20bit/libwkhtmltox.so

After install of libgdiplus in microsoft/dotnet:1.1.2-runtime image libwkhtmltox library is found.

image

Dockerfile:

FROM microsoft/dotnet:1.1.2-runtime

RUN ["apt-get", "update"]
RUN ["apt-get", "-y", "install", "libgdiplus"]

WORKDIR /app

COPY / .

ENTRYPOINT ["dotnet", "DinkToPfd.TestConsoleApp.dll"]

Result: 636370886662487690.pdf

Thanks @Ahmed-Raouf for pointing this out.

I deployed my application on Linux and it works. But I installed libgdiplus as I needed it in Captcha component which I use in my application. I don’t know if wkhtmltopdf depends on it or not. Try to install it. Hope this fix your problem.

sudo apt-get install libgdiplus

And how do you using it in the code? I am running .NET Core 2.0 and i registered converter as:

services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools()));

and i am using it as _converter.Convert(MyDoc), injected as IConverter from constructor.

I tried to install all the suggestions from your comments, still unable to load dll in docker container.

Dockerfile:

FROM microsoft/aspnetcore:2.0 AS base

WORKDIR /app

FROM microsoft/aspnetcore-build:2.0 AS build
WORKDIR /src
COPY MyProj/MyProj.csproj MyProj/
RUN dotnet restore MyProj/MyProj.csproj
COPY . .
WORKDIR /src/MyProj
RUN dotnet build MyProj.csproj -c Release -o /app

FROM build AS publish
RUN dotnet publish MyProj.csproj -c Release -o /app

FROM base AS final

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        zlib1g \
        fontconfig \
        libfreetype6 \
        libx11-6 \
        libxext6 \
        libxrender1 \
    && curl -o /usr/lib/libwkhtmltox.so \
        --location \
        https://github.com/rdvojmoc/DinkToPdf/raw/v1.0.8/v0.12.4/64%20bit/libwkhtmltox.so

WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "MyProj.dll"]

UPDATE:

This actually works, so just use this way instead registering and adding DLL manually, as i tried before this post. Hope this helps someone…

After 4 days it worked. Thank you

@fernandovictorTI, I believe the problem is that the second stage of your build (runtime) is not running the below command again, so libwkhtmltox and it’s dependencies are left in the first stage (build).

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        zlib1g \
        fontconfig \
        libfreetype6 \
        libx11-6 \
        libxext6 \
        libxrender1 \
    && curl -o /usr/lib/libwkhtmltox.so \
        --location \
        https://github.com/rdvojmoc/DinkToPdf/raw/v1.0.8/v0.12.4/64%20bit/libwkhtmltox.so

this helped to me

Hi @fernandovictorTI, here’s the RUN command I used:

# Download libwkhtmltox and install it's dependencies
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        zlib1g \
        fontconfig \
        libfreetype6 \
        libx11-6 \
        libxext6 \
        libxrender1 \
    && curl -o /usr/lib/libwkhtmltox.so \
        --location \
        https://github.com/rdvojmoc/DinkToPdf/raw/v1.0.8/v0.12.4/64%20bit/libwkhtmltox.so

Results may vary depending on the source image you’re using. In my case I’m using microsoft/dotnet:2.0-sdk-stretch.

In case someone else runs into this problem when running tests (inside a Docker container or in a Linux host), adding libgdiplus to the image didn’t do the trick for me.

I checked libwkhtmltox.so with ldd and libgdiplus is not found as a dependency:

        # ldd libwkhtmltox.so 
	linux-vdso.so.1 (0x00007ffc29de1000)
	libXrender.so.1 => /usr/lib/x86_64-linux-gnu/libXrender.so.1 (0x00007f628c25d000)
	libfontconfig.so.1 => /usr/lib/x86_64-linux-gnu/libfontconfig.so.1 (0x00007f628c01f000)
	libfreetype.so.6 => /usr/lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007f628bd70000)
	libXext.so.6 => /usr/lib/x86_64-linux-gnu/libXext.so.6 (0x00007f628bb5e000)
	libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007f628b81e000)
	libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f628b604000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f628b400000)
	librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f628b1f8000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f628afdb000)
	libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f628ac59000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f628a955000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f628a73e000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f628a39f000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f628f1a2000)
	libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007f628a175000)
	libpng16.so.16 => /usr/lib/x86_64-linux-gnu/libpng16.so.16 (0x00007f6289f42000)
	libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f6289d1a000)
	libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007f6289b16000)
	libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f6289910000)
	libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007f62896fa000)

What worked for me, for running tests, was to copy libwkhtmltox.so to /usr/lib directory.

@miguelalvarezi Thank you for your help, I just forgot to answer that it is ok and it works.

Currently, requirenmets for pdf files were changed (need to support different headers for pages) and now I use .net core node services and nodejs html-pdf utility. I was wonder how fast it works.

For those still researching, my problem was that I was including all 3 libraries (.dll / .so / .dylib) in my .Net Core 5 WebAPI distributable on the AWS EC2 instance. Deleting 2 of them, just leaving the .so, and installing wkpdftohtml on the instance, solved the problem.

@fernandovictorTI, if you can share your Dockerfile I can review it and maybe give you some guidance.

Try to add the files: libwkhtmltox.dll libwkhtmltox.dylib libwkhtmltox.so on the root folder.

Hi,

I tried to run example DinkToPdf.TestConsoleApp on Ubuntu 16.04 LTS without problems. image

Make sure that libwkhtmltox.so is placed in root folder (where your main project .dll is) of your project and is named correctly (libwkhtmltox).