Rotativa.AspNetCore
Rotativa.AspNetCore copied to clipboard
Images not working when using from ubuntu docker
Hello,
Not sure if someone struggled with this. I'm testing the library from Windows and have no problems rendering pdfs with links to external public images, but when deploying to an ubuntu docker, images are not shown in the pdf generated. Checked all the permissions to the libraries and I have no problem.
I made sure the docker has internet access and gave permissions to both wkhtmltopdf and wkhtmltoimage (followed this link: https://github.com/webgio/Rotativa.AspNetCore/issues/17)
does anyone have any idea?
Thanks!
Hi, the wkhtmltopdf on linux needs some packages to work fine, if you installed the package (wkhtmltopdf.deb) in you pc and just copied the file wkhtmltopdf to the application folder, this can cause some problems. The correct is you extract and install the package in the docker image and install all dependencies. Here it work fine to me. but I use one abstraction of docker, my application runs in azure linux web app.
try these steps:
- open the cmd
docker exec -u 0 -it mycontainer bash
- update the packages
apt-get update
- install sudo
apt-get -y install sudo
- unpack the package
dpkg -i wkhtmltox.deb
- install the dependencies
apt-get -f install
- unpack the package again
dpkg -i wkhtmltox.deb
- copy the generated file to your application folder
sudo cp /usr/local/bin/wkhtmltopdf ~/site/wwwroot/wwwroot/Rotativa
Install the packages with a script similar to this:
#!/bin/sh
apt update
apt -y install wget
### Debian 10 ### (change to your operating system)
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.buster_amd64.deb
apt install -f -y ./wkhtmltox_0.12.6-1.buster_amd64.deb
### Copy files ###
cp -f /usr/local/bin/wkhtmltopdf ~/site/wwwroot/wwwroot/Rotativa
cp -f /usr/local/bin/wkhtmltoimage ~/site/wwwroot/wwwroot/Rotativa
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.
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.