DinkToPdf icon indicating copy to clipboard operation
DinkToPdf copied to clipboard

Unable to load shared library '/app/libwkhtmltox.so' or one of its dependencies. In order to help diagnose loading problems,

Open sanjeev02saraswat opened this issue 2 years ago • 10 comments

I am trying to create container for one .net core api . we are using dinktopdf dll for html to pdf pages.it is working fine in iis express but getting error when creating image and container in linux env.

Below is my docker file content:

FROM mcr.microsoft.com/dotnet/aspnet:2.1 AS base WORKDIR /app EXPOSE 80

FROM mcr.microsoft.com/dotnet/sdk:2.1 AS build WORKDIR /src COPY ["ProcessAPI/ProcessAPI.csproj", "ProcessAPI/"] RUN dotnet restore "ProcessAPI/ProcessAPI.csproj" COPY . . WORKDIR "/src/ProcessAPI" RUN dotnet build "ProcessAPI.csproj" -c Release -o /app/build

FROM build AS publish RUN dotnet publish "ProcessAPI.csproj" -p:PublishProfile=/Properties/PublishProfiles/FolderProfile.pubxml -c Release -o /app/publish

FROM base AS final WORKDIR /app COPY --from=publish /app/publish .

RUN apt-get update RUN apt-get install wget libgdiplus -y RUN wget -P /app https://github.com/rdvojmoc/DinkToPdf/raw/master/v0.12.4/64%20bit/libwkhtmltox.dll RUN wget -P /app https://github.com/rdvojmoc/DinkToPdf/raw/master/v0.12.4/64%20bit/libwkhtmltox.dylib RUN wget -P /app https://github.com/rdvojmoc/DinkToPdf/raw/master/v0.12.4/64%20bit/libwkhtmltox.so

ENTRYPOINT ["dotnet", "ProcessAPI.dll"]

I am working on this issue from last 2 days but no success. Please suggest how we can come out from this issue.

sanjeev02saraswat avatar Aug 31 '21 10:08 sanjeev02saraswat

I tried a lot of method to solve this problem before but real reason is very surprised me. We are always trying install libgdiplus library in final step however this is wrong. Edited Docker file:

FROM mcr.microsoft.com/dotnet/aspnet:2.1 AS base
RUN apt-get update && apt-get install -y --allow-unauthenticated libgdiplus
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/sdk:2.1 AS build
WORKDIR /src
COPY ["ProcessAPI/ProcessAPI.csproj", "ProcessAPI/"]
RUN dotnet restore "ProcessAPI/ProcessAPI.csproj"
COPY . .
WORKDIR "/src/ProcessAPI"
RUN dotnet build "ProcessAPI.csproj" -c Release -o /app/build
 
FROM build AS publish
RUN dotnet publish "ProcessAPI.csproj" -p:PublishProfile=/Properties/PublishProfiles/FolderProfile.pubxml -c Release -o /app/publish
 
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish . 

ENTRYPOINT ["dotnet", "ProcessAPI.dll"]

In addition, libwkhtmltox.dll, libwkhtmltox.dylib and libwkhtmltox.so files should be in next to .csproj file

emrehorasan avatar Sep 08 '21 06:09 emrehorasan

emrehorasan

I attempted your solution and installed several dependencies, but unfortunately, it did not work as expected.

Currently, I am using a Linux container, and I encountered the following error: "One or more errors occurred. (Unable to load shared library 'libwkhtmltox' or one of its dependencies)."

I attempted using the packages listed below.

RUN apt-get install -y --allow-unauthenticated libgdiplus RUN apt-get install xvfb libfontconfig wkhtmltopdf libc6-dev openssl libssl-dev -y RUN apt-get install libxrender1 libfontconfig1 libxext-dev -y

svap-roshan avatar Jun 30 '23 09:06 svap-roshan

emrehorasan

I attempted your solution and installed several dependencies, but unfortunately, it did not work as expected.

Currently, I am using a Linux container, and I encountered the following error: "One or more errors occurred. (Unable to load shared library 'libwkhtmltox' or one of its dependencies)."

I attempted using the packages listed below.

RUN apt-get install -y --allow-unauthenticated libgdiplus

RUN apt-get install xvfb libfontconfig wkhtmltopdf libc6-dev openssl libssl-dev -y

RUN apt-get install libxrender1 libfontconfig1 libxext-dev -y

You should put the dependency files next to .csproj file and should import these files to the project. I inspected your error and am guessing that it is depended .dll and other files. Nowdays I am using .net 7 version and still works. If you want I can share content of my docker file.

emrehorasan avatar Jun 30 '23 10:06 emrehorasan

emrehorasan

I attempted your solution and installed several dependencies, but unfortunately, it did not work as expected. Currently, I am using a Linux container, and I encountered the following error: "One or more errors occurred. (Unable to load shared library 'libwkhtmltox' or one of its dependencies)." I attempted using the packages listed below. RUN apt-get install -y --allow-unauthenticated libgdiplus RUN apt-get install xvfb libfontconfig wkhtmltopdf libc6-dev openssl libssl-dev -y RUN apt-get install libxrender1 libfontconfig1 libxext-dev -y

You should put the dependency files next to .csproj file and should import these files to the project. I inspected your error and am guessing that it is depended .dll and other files. Nowdays I am using .net 7 version and still works. If you want I can share content of my docker file.

Firstly, thank you for your quick response.

I attempted to relocate the file next to the .csproj itself and below the DLLs present in the root directory:

libwkhtmltox.dll libwkhtmltox.dylib libwkhtmltox.so

Even I'm using .NET 7. If possible, it would be greatly appreciated if you could provide the content of Dockerfile.

Here is the code from my Dockerfile, along with the various packages I have tried in my attempts to resolve the issue.

FROM mcr.microsoft.com/dotnet/aspnet:7.0.8-bullseye-slim-arm64v8 AS base
RUN apt-get update
RUN apt-get install -y --allow-unauthenticated libgdiplus
RUN apt-get install xvfb libfontconfig wkhtmltopdf libc6-dev openssl libssl-dev -y
RUN apt-get install libxrender1 libfontconfig1 libxext-dev -y
WORKDIR /app
EXPOSE 80
# copy csproj and restore as distinct layers
FROM mcr.microsoft.com/dotnet/sdk:7.0.305-bullseye-slim-arm64v8 AS build
WORKDIR /src
COPY *.sln .
COPY ["PdfApp/PdfApp.csproj", "PdfApp/"]
RUN wget -P /src https://github.com/rdvojmoc/DinkToPdf/raw/master/v0.12.4/64%20bit/libwkhtmltox.dll
RUN wget -P /src https://github.com/rdvojmoc/DinkToPdf/raw/master/v0.12.4/64%20bit/libwkhtmltox.dylib
RUN wget -P /src https://github.com/rdvojmoc/DinkToPdf/raw/master/v0.12.4/64%20bit/libwkhtmltox.so
RUN dotnet restore "PdfApp/PdfApp.csproj"
# copy and publish app and libraries
COPY . .
WORKDIR "/src/PdfApp"
RUN dotnet build "PdfApp.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "PdfApp.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "PdfApp.dll"]

svap-roshan avatar Jun 30 '23 11:06 svap-roshan

emrehorasan

I attempted your solution and installed several dependencies, but unfortunately, it did not work as expected.

Currently, I am using a Linux container, and I encountered the following error: "One or more errors occurred. (Unable to load shared library 'libwkhtmltox' or one of its dependencies)."

I attempted using the packages listed below.

RUN apt-get install -y --allow-unauthenticated libgdiplus

RUN apt-get install xvfb libfontconfig wkhtmltopdf libc6-dev openssl libssl-dev -y

RUN apt-get install libxrender1 libfontconfig1 libxext-dev -y

You should put the dependency files next to .csproj file and should import these files to the project. I inspected your error and am guessing that it is depended .dll and other files. Nowdays I am using .net 7 version and still works. If you want I can share content of my docker file.

Firstly, thank you for your quick response.

I attempted to relocate the file next to the .csproj itself and below the DLLs present in the root directory:

libwkhtmltox.dll

libwkhtmltox.dylib

libwkhtmltox.so

Even I'm using .NET 7. If possible, it would be greatly appreciated if you could provide the content of Dockerfile.

Here is the code from my Dockerfile, along with the various packages I have tried in my attempts to resolve the issue.


FROM mcr.microsoft.com/dotnet/aspnet:7.0.8-bullseye-slim-arm64v8 AS base

RUN apt-get update

RUN apt-get install -y --allow-unauthenticated libgdiplus

RUN apt-get install xvfb libfontconfig wkhtmltopdf libc6-dev openssl libssl-dev -y

RUN apt-get install libxrender1 libfontconfig1 libxext-dev -y

WORKDIR /app

EXPOSE 80

# copy csproj and restore as distinct layers

FROM mcr.microsoft.com/dotnet/sdk:7.0.305-bullseye-slim-arm64v8 AS build

WORKDIR /src

COPY *.sln .

COPY ["PdfApp/PdfApp.csproj", "PdfApp/"]

RUN wget -P /src https://github.com/rdvojmoc/DinkToPdf/raw/master/v0.12.4/64%20bit/libwkhtmltox.dll

RUN wget -P /src https://github.com/rdvojmoc/DinkToPdf/raw/master/v0.12.4/64%20bit/libwkhtmltox.dylib

RUN wget -P /src https://github.com/rdvojmoc/DinkToPdf/raw/master/v0.12.4/64%20bit/libwkhtmltox.so

RUN dotnet restore "PdfApp/PdfApp.csproj"

# copy and publish app and libraries

COPY . .

WORKDIR "/src/PdfApp"

RUN dotnet build "PdfApp.csproj" -c Release -o /app/build

FROM build AS publish

RUN dotnet publish "PdfApp.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final

WORKDIR /app

COPY --from=publish /app/publish .

ENTRYPOINT ["dotnet", "PdfApp.dll"]

Here is my docker file:

FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base ENV TZ=Europe/Istanbul RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone RUN apt-get update && apt-get install -y --allow-unauthenticated libgdiplus WORKDIR /app EXPOSE 80

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build WORKDIR /src COPY ["Api.csproj"] RUN dotnet restore "Api.csproj" COPY . . WORKDIR "/src" RUN dotnet build "Api.csproj" -c Release -o /app/build

FROM build AS publish RUN dotnet publish "Api.csproj" -c Release -o /app/publish RUN date >> /app/publish/.env

FROM base AS final WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "Api.dll"]

emrehorasan avatar Jun 30 '23 11:06 emrehorasan

In addition here is my project file: image

emrehorasan avatar Jun 30 '23 11:06 emrehorasan

I have the same settings, and I'm also exporting the DLL in the .csproj file.

svap-roshan avatar Jun 30 '23 11:06 svap-roshan

Hi @emrehorasan. I've just your configuration of Dockerfile and it's working correctly on Linux (don't have a problem with dependencies). But when I want to use the Convert method from DinkToPdf, it always returns an empty byte[] on Linux. (on Windows there return some bytes).

If I am using ObjectSettings.Page = url from the page, there is this problem. Otherwise, if I am using ObjectSettings.HtmlContent = some content(string), then will generate correctly. This is only on Linux behavior.

A similar problem was described here: https://stackoverflow.com/questions/72901484/dinktopdf-converter-returns-empty-byte-array-on-ubuntu

Are you using a different method to convert HtmlToPdfDocument to byte[]?

In logs in Linux there are: QSslSocket: cannot resolve CRYPTO_num_locks QSslSocket: cannot resolve CRYPTO_set_id_callback QSslSocket: cannot resolve CRYPTO_set_locking_callback QSslSocket: cannot resolve sk_free QSslSocket: cannot resolve sk_num QSslSocket: cannot resolve sk_pop_free QSslSocket: cannot resolve sk_value QSslSocket: cannot resolve SSL_library_init QSslSocket: cannot resolve SSL_load_error_strings QSslSocket: cannot resolve SSLv3_client_method

and then there is an empty array.

Thanks a lot!

Bartosz97 avatar Jul 01 '23 10:07 Bartosz97

I have a solution which worked for me with .net core 6 used in docker. This solved the error "Unable to load shared library 'libwkhtmltox' or one of its dependencies.".

  1. Make sure you have all libwkhtmltox files (in fact on linux you need only .so file) in 64bit or 32bit depending on your linux container (in my case it is 64bit) in your built project folder. You can copy them manually OR place them into project before building and mark them in visual studio "Copy to output directory" -> "Always" OR you can download these files during making docker image inside dockerfile. The choice is yours.
  2. Go into the docker cointainer to /app where your project is and run command "ldd libwkhtmltox.so". This gave me the result:

linux-vdso.so.1 (0x00007ffcfd39c000) libXrender.so.1 => not found libfontconfig.so.1 => not found libfreetype.so.6 => not found libXext.so.6 => not found libX11.so.6 => not found libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f0bbe6d8000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f0bbe6d2000) librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f0bbe6c8000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f0bbe6a6000) libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f0bbe4d9000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f0bbe395000) libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f0bbe379000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f0bbe1a5000) /lib64/ld-linux-x86-64.so.2 (0x00007f0bc1436000)

As you can see some of the dependencies are not found soooo...

  1. Install all the lacking dependencies and it should work. You can try it inside container terminal to see if it works or just place it in the dockerfile and build again: RUN apt-get update && apt-get install -y --allow-unauthenticated apt-utils libc6-dev libxrender1 libfontconfig1 libgdiplus libjpeg62-turbo libfontconfig1 libfreetype6 libxext6 libx11-6 fontconfig zlib1g

  2. My final dockerfile looks like that:

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
RUN apt-get update && apt-get install -y --allow-unauthenticated apt-utils libc6-dev libxrender1 libfontconfig1 libgdiplus libjpeg62-turbo libfontconfig1 libfreetype6 libxext6 libx11-6 fontconfig zlib1g
.... rest of the file and commands ...
  1. DinkToPdf must work on docker (linux) and if it doesn't then you have messed up configuration and it is solvable. Cheers!

WojGrab avatar Jan 17 '24 10:01 WojGrab

@WojGrab

Thanks! This worked for me.

SaqlainJanAli avatar Apr 04 '24 05:04 SaqlainJanAli