Rotativa.AspNetCore icon indicating copy to clipboard operation
Rotativa.AspNetCore copied to clipboard

how to run on Linux docker

Open Leonidnei opened this issue 6 years ago • 13 comments

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.

Leonidnei avatar Apr 02 '18 12:04 Leonidnei

I'm on the same situation here @Leonidnei . Did you find any solution?

lucasvdaros avatar Apr 11 '18 17:04 lucasvdaros

We bypassed this by using Linux version of wkhtmltopdf without Rotativa, we just take html from DOM and invoke wkhtmltopdf to create PDF

Leonidnei avatar Apr 12 '18 12:04 Leonidnei

Hi @Leonidnei. How are you invoking wkhtmltopdf? If possible show an example.

fernandovictorTI avatar May 15 '18 19:05 fernandovictorTI

We start wkhtmltopdf process passing input html file and output pdf files as arguments.

Leonidnei avatar May 16 '18 03:05 Leonidnei

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.

heitorb avatar May 25 '18 17:05 heitorb

We managed to get it running by following these steps:

  1. Download the wkhtmltopdf Linux binaries from https://wkhtmltopdf.org/downloads.html

  2. Install the Linux wkhtmltopdf libraries/dependencies on the Linux machine apt-get update apt-get install -y libx11-dev libfontconfig libxrender1 libxext6

  3. Extract and copy all the content from the downloaded binaries to /usr

  4. Copy the two binaries wkhtmltopdf and wkhtmltoimage from the downloaded and extracted bin folder to the out/WkHtmlToPdf folder with your published files

  5. Rename the binaries wkhtmltopdf to wkhtmltopdf.exe and wkhtmltoimage to wkhtmltoimage.exe

This way we could use Rotativa and wkhtmltopdf together

cbterceiro avatar May 25 '18 17:05 cbterceiro

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

fernandovictorTI avatar May 25 '18 18:05 fernandovictorTI

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

ghost avatar Oct 26 '18 07:10 ghost

We managed to get it running by following these steps:

  1. Download the wkhtmltopdf Linux binaries from https://wkhtmltopdf.org/downloads.html
  2. Install the Linux wkhtmltopdf libraries/dependencies on the Linux machine apt-get update apt-get install -y libx11-dev libfontconfig libxrender1 libxext6
  3. Extract and copy all the content from the downloaded binaries to /usr
  4. Copy the two binaries wkhtmltopdf and wkhtmltoimage from the downloaded and extracted bin folder to the out/WkHtmlToPdf folder with your published files
  5. Rename the binaries wkhtmltopdf to wkhtmltopdf.exe and wkhtmltoimage to wkhtmltoimage.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.

yashvit avatar Jan 17 '19 06:01 yashvit

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!

yashvit avatar Jan 17 '19 07:01 yashvit

I can confirm that the process described by @yashvit works fine for me.

Dev-Owl avatar Feb 17 '19 15:02 Dev-Owl

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

barisates avatar Jun 18 '20 12:06 barisates

the solution by @yashvit work fine to me.

willpower18 avatar May 14 '21 03:05 willpower18