I've got an Azure Function (not container function) that uses DinkToPdf.
I've upgraded this to .NET 6 and Azure V4.
I now get this error:
One or more errors occurred. (Unable to load shared library '/home/site/wwwroot/bin/libwkhtmltox.so' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libXrender.so.1: cannot open shared object file: No such file or directory)
I've checked the deployed bundle and libqkhtmltox.so
exists, so reading further down the error, I assume that libXrender.so.1
is missing on the system.
I've seen various other answers on here that suggest just apt install libxrender1
to fix this, but since I'm not in a containerised function, I don't think I can do that.
Are there any workarounds here?
Has libXrender
been upgraded in V4, if so, can I manually load in libXrender.so.x
and hope it works? Is there a nuget package I can use to bundle in libXrender.so.1
?
It seems as though Microsoft has removed a whole bunch of dependencies around libgdiplus
from the standard runtime container. I'm sure those aren't the only ones.
So, the answer is to migrate your function to use a custom runtime container.
This dockerfile should do the job:
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS installer-env
COPY . /src/dotnet-function-app
RUN cd /src/dotnet-function-app && \
mkdir -p /home/site/wwwroot && \
dotnet publish your-project.csproj --output /home/site/wwwroot
FROM mcr.microsoft.com/azure-functions/dotnet:4
RUN apt-get update && apt-get install -y libglib2.0 libgdiplus libnss3 libatk1.0-0 libatk-bridge2.0-0 ca-certificates fonts-liberation libappindicator3-1 libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 lsb-release xdg-utils
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
COPY --from=installer-env ["/home/site/wwwroot", "/home/site/wwwroot"]
I'm not saying this is the optimal container, but it does contain everything needed for both pupetteer
/chrome-headless
and dink2pdf
to work. If you just want dink2pdf
, you might only need libgdiplus
in that dependency install line (I've not tested it though).