Attention: This page contains partner and advertising links. Therefore this page is to be understood entirety as an advertisement!
Those who want to create PDF files on the server side have a wide range of possibilities depending on the used programming language and frameworks. I develop my server applications mostly on the basis of the Symfony framework. So I create corresponding PDF files by converting clean HTML with the tool wkhtmltopdf.The whole thing is also simplified by the Symfony bundle Snappy
Only the installation of wkhtmltopdf is somehow more complicated, especially if this has to happen automatically on the infrastructure of Amazon Webservices. An instruction:
The installation on AmazonsElastic Beanstalk is controlled by a .config
file, which is located in a folder called .ebextensions
and bundled with the application package to the server. The name of the file is not important, I baptized it install-wkhtmltopdf.config
.
The following configuration executes six linux commands in sequence to install wkhtmltopdf:
.ebextensions/install-wkhtmltopdf.config
container_commands:
1_install_wkhtmltopdf:
command: yum -y install fontconfig libXrender libXext xorg-x11-fonts-Type1 xorg-x11-fonts-75dpi freetype libpng zlib libjpeg-turbo openssl icu
ignoreErrors: true
2_install_wkhtmltopdf:
# see: https://wkhtmltopdf.org/downloads.html for updates
command: wget https://downloads.wkhtmltopdf.org/0.12/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz --dns-timeout=5 --connect-timeout=5
test: test ! -f .wkhtmltopdf
3_install_wkhtmltopdf:
command: tar -xJf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
test: test ! -f .wkhtmltopdf
4_install_wkhtmltopdf:
command: cp wkhtmltox/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf
test: test ! -f .wkhtmltopdf
5_install_wkhtmltopdf:
command: cp wkhtmltox/bin/wkhtmltoimage /usr/local/bin/wkhtmltoimage
test: test ! -f .wkhtmltopdf
6_install_wkhtmltopdf:
command: touch .wkhtmltopdf
The manually generated .wkhtmltopdf
file ensures that wkhtmltopdf is not reinstalled every time the software application is updated, but only when it is actually missing.
If you do not use the Elastic Beanstalk as a comfortable container and rely on individually adapted EC2 machines you can also enter the commands manually in the console manually:
yum -y install fontconfig libXrender libXext xorg-x11-fonts-Type1 xorg-x11-fonts-75dpi freetype libpng zlib libjpeg-turbo openssl icu
wget https://downloads.wkhtmltopdf.org/0.12/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz --dns-timeout=5 --connect-timeout=5
tar -xJf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
cp wkhtmltox/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf
cp wkhtmltox/bin/wkhtmltoimage /usr/local/bin/wkhtmltoimage