Rotativa.AspNetCore
Rotativa.AspNetCore copied to clipboard
how to run on Linux docker
Actually this is a question: the page mentions wkhtmltopdf.exe, so does it run on Linux? We'd like to run Asp.Net core code inside Linux container.
I'm on the same situation here @Leonidnei . Did you find any solution?
We bypassed this by using Linux version of wkhtmltopdf without Rotativa, we just take html from DOM and invoke wkhtmltopdf to create PDF
Hi @Leonidnei. How are you invoking wkhtmltopdf? If possible show an example.
We start wkhtmltopdf process passing input html file and output pdf files as arguments.
So, is there a solution for this WITH Rotativa? Cool that you can get it to work without it, but it would be even better if it would work, since .NET Core runs on Linux, this should support it also.
We managed to get it running by following these steps:
-
Download the wkhtmltopdf Linux binaries from https://wkhtmltopdf.org/downloads.html
-
Install the Linux wkhtmltopdf libraries/dependencies on the Linux machine
apt-get update
apt-get install -y libx11-dev libfontconfig libxrender1 libxext6
-
Extract and copy all the content from the downloaded binaries to
/usr
-
Copy the two binaries
wkhtmltopdf
andwkhtmltoimage
from the downloaded and extractedbin
folder to theout/WkHtmlToPdf
folder with your published files -
Rename the binaries
wkhtmltopdf
towkhtmltopdf.exe
andwkhtmltoimage
towkhtmltoimage.exe
This way we could use Rotativa and wkhtmltopdf together
This command worked for me.
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 works for me in an Alpine container:
RUN apk add --update --no-cache \
libgcc \
libstdc++ \
libx11 \
glib \
libxrender \
libxext \
libintl \
libcrypto1.0 \
libssl1.0 \
ttf-dejavu \
ttf-droid \
ttf-freefont \
ttf-liberation \
ttf-ubuntu-font-family
See: https://github.com/madnight/docker-alpine-wkhtmltopdf/blob/master/Dockerfile
We managed to get it running by following these steps:
- Download the wkhtmltopdf Linux binaries from https://wkhtmltopdf.org/downloads.html
- Install the Linux wkhtmltopdf libraries/dependencies on the Linux machine
apt-get update
apt-get install -y libx11-dev libfontconfig libxrender1 libxext6
- Extract and copy all the content from the downloaded binaries to
/usr
- Copy the two binaries
wkhtmltopdf
andwkhtmltoimage
from the downloaded and extractedbin
folder to theout/WkHtmlToPdf
folder with your published files- Rename the binaries
wkhtmltopdf
towkhtmltopdf.exe
andwkhtmltoimage
towkhtmltoimage.exe
This way we could use Rotativa and wkhtmltopdf together
I tried doing this. Installed wkhtmltopdf on ubuntu, copied the binary to the Rotativa folder in my webapp and renamed it to .exe
But it still does not work.
Update:
Looking at the code here: https://github.com/webgio/Rotativa.AspNetCore/blob/master/Rotativa.AspNetCore/WkhtmltopdfDriver.cs
On linux platform it does not require the .exe in the filename.
So the steps that worked for me on Ubuntu 16.04:
- Download the .deb package from https://wkhtmltopdf.org/downloads.html
-
sudo dpkg -i <path to deb package>
- Install missing dependencies using apt
sudo apt -f install
-
sudo cp /usr/local/bin/wkhtmltopdf <path to web app>/wwwroot/Rotativa
- fix permissions etc
- It Works!
I can confirm that the process described by @yashvit works fine for me.
Update:
Looking at the code here: https://github.com/webgio/Rotativa.AspNetCore/blob/master/Rotativa.AspNetCore/WkhtmltopdfDriver.cs
On linux platform it does not require the .exe in the filename.
So the steps that worked for me on Ubuntu 16.04:
- Download the .deb package from https://wkhtmltopdf.org/downloads.html
sudo dpkg -i <path to deb package>
- Install missing dependencies using apt
sudo apt -f install
sudo cp /usr/local/bin/wkhtmltopdf <path to web app>/wwwroot/Rotativa
- fix permissions etc
- It Works!
I shared the example running on the Docker Linux (bionic) container in Windows environment. https://github.com/barisates/rotativa-pdf-dotnet-core-docker-example
the solution by @yashvit work fine to me.