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

How to run on Ubuntu?

Open vivekanandpv opened this issue 6 years ago • 14 comments

My Asp.net core 2.1 app is working perfectly with Rotativa on Windows machine. But when I publish it to my Linux (Ubuntu 16.x) server (I am not using docker), I get 500 internal server error whenever the PDF generation is invoked. I have so far installed wkhtmltopdf on my Linux server, but couldn't figure out how to configure. Please help.

vivekanandpv avatar Sep 30 '18 20:09 vivekanandpv

You can try to set the path to your wkhtmltopdf, but I think it won't work. I have the same issue and will create the pull request.

vbondarev avatar Nov 13 '18 05:11 vbondarev

My Asp.net core 2.1 app is working perfectly with Rotativa on Windows machine. But when I publish it to my Linux (Ubuntu 16.x) server (I am not using docker), I get 500 internal server error whenever the PDF generation is invoked. I have so far installed wkhtmltopdf on my Linux server, but couldn't figure out how to configure. Please help.

You can use my fork https://github.com/vbondarev/Rotativa.AspNetCore/tree/develop

vbondarev avatar Dec 12 '18 08:12 vbondarev

For me to correct this error I had to put these files that are available in the link below: https://github.com/MatheusNCarvalho/wkhtmltox-0.12.4 and my Dockerfile looks like this:

### Stage 1 - Obtain the source and generate the Build ###
FROM microsoft/dotnet:2.2-sdk AS build-env
WORKDIR /app

### Copy and restore dependencies ###
COPY . /app
RUN dotnet restore Teste.csproj
RUN dotnet publish Teste.csproj -c Release -o /app/publish


### Stage 2 - Upload the application through the binaries ###
## Build da imagem ###

FROM microsoft/dotnet:2.2-aspnetcore-runtime

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

WORKDIR /app
COPY --from=build-env /app/publish .

RUN chmod 755 /app/wwwroot/Rotativa/wkhtmltopdf
RUN chmod 755 /app/wwwroot/Rotativa/wkhtmltoimage


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

MatheusNCarvalho avatar Apr 01 '19 18:04 MatheusNCarvalho

For me to correct this error I had to put these files that are available in the link below: https://github.com/MatheusNCarvalho/wkhtmltox-0.12.4 and my Dockerfile looks like this:

### Stage 1 - Obtain the source and generate the Build ###
FROM microsoft/dotnet:2.2-sdk AS build-env
WORKDIR /app

### Copy and restore dependencies ###
COPY . /app
RUN dotnet restore Teste.csproj
RUN dotnet publish Teste.csproj -c Release -o /app/publish


### Stage 2 - Upload the application through the binaries ###
## Build da imagem ###

FROM microsoft/dotnet:2.2-aspnetcore-runtime

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

WORKDIR /app
COPY --from=build-env /app/publish .

RUN chmod 755 /app/wwwroot/Rotativa/wkhtmltopdf
RUN chmod 755 /app/wwwroot/Rotativa/wkhtmltoimage


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

Thankyou very much, i am struggling to fix for this error when deploying in Ubuntu 18.04, the error says "No Such File or Directory"

lutfiarahmanda avatar Jan 07 '20 01:01 lutfiarahmanda

For me to correct this error I had to put these files that are available in the link below: https://github.com/MatheusNCarvalho/wkhtmltox-0.12.4 and my Dockerfile looks like this:

### Stage 1 - Obtain the source and generate the Build ###
FROM microsoft/dotnet:2.2-sdk AS build-env
WORKDIR /app

### Copy and restore dependencies ###
COPY . /app
RUN dotnet restore Teste.csproj
RUN dotnet publish Teste.csproj -c Release -o /app/publish


### Stage 2 - Upload the application through the binaries ###
## Build da imagem ###

FROM microsoft/dotnet:2.2-aspnetcore-runtime

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

WORKDIR /app
COPY --from=build-env /app/publish .

RUN chmod 755 /app/wwwroot/Rotativa/wkhtmltopdf
RUN chmod 755 /app/wwwroot/Rotativa/wkhtmltoimage


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

I tried this but the images and styles are not displayed correctly. Do I have to include all files and folders from https://github.com/MatheusNCarvalho/wkhtmltox-0.12.4/tree/master/Rotativa or did you include only wkhtmltopdf and wkhtmltoimage?

vborza avatar Jan 21 '20 10:01 vborza

Hi @vborza ! I have the same problem: images and styles are not displayed correctly too! Do you solved the problem?

jlnpinheiro avatar Feb 25 '20 01:02 jlnpinheiro

Hi @vborza ! I have the same problem: images and styles are not displayed correctly too! Do you solved the problem?

I've solved it following this approach.... https://github.com/webgio/Rotativa.AspNetCore/issues/7#issuecomment-455063816

vborza avatar Feb 25 '20 07:02 vborza

@MatheusNCarvalho on Linux whith Docker container, PDFs are generated without CSS formatting and images not showed, but on Windows without contantainer, PDF successfully generated. Did you have this problem?

jlnpinheiro avatar Feb 26 '20 00:02 jlnpinheiro

@MatheusNCarvalho on Linux whith Docker container, PDFs are generated without CSS formatting and images not showed, but on Windows without contantainer, PDF successfully generated. Did you have this problem?

Yes, how did you fixed it?

ayazzali avatar Mar 28 '20 16:03 ayazzali

@ayazzali I fix this problem, put physical file reference (using "file://") in and tags. Look at this example https://github.com/jlnpinheiro/bufunfa/blob/master/src/frontend/web/bufunfa-web/Helpers/CustomHtmlHelper.cs. See "CriarTagLinkCssPorOS" method. Only this way works for my on Docker environment.

jlnpinheiro avatar Mar 29 '20 02:03 jlnpinheiro

@ayazzali I fix this problem, put physical file reference (using "file://") in and tags. Look at this example https://github.com/jlnpinheiro/bufunfa/blob/master/src/frontend/web/bufunfa-web/Helpers/CustomHtmlHelper.cs. See "CriarTagLinkCssPorOS" method. Only this way works for my on Docker environment.

Thx, but today I'l did debuging, and found another "fix" see https://github.com/webgio/Rotativa.AspNetCore/issues/60#issuecomment-605624966

ayazzali avatar Mar 29 '20 11:03 ayazzali

@vivekanandpv maybe close issue?

ayazzali avatar Mar 29 '20 12:03 ayazzali

This is probably because Rotativa injects the base URL property in your HTML. See https://github.com/webgio/Rotativa.AspNetCore/issues/60#issuecomment-605624966 . The base URL is set to the internal port your website is listening to, but that port is only accessible by docker. Another port is used for incoming requests.

The fix of @jlnpinheiro works because by setting the absolute path the base URL isn't used anymore.

Setting the base URL by Rotativa shouldn't be necessary, as in my opinion you should set the base URL yourself in the HTML if your site needs it. In PR #92 an option is added to disable setting the base URL (setBaseUrl: false), which should fix the issue.

ArjanKw avatar Aug 16 '24 10:08 ArjanKw