Add pdf poster generation to ci pipeline

Change-Id: Ib18a3f2572d18e1f9dee7c4be83056040289a2b1
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 0dc13c3..1ef0245 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -23,7 +23,11 @@
 
     - start_section install_linux_packages "Installing missing Linux packages"
     - apt-get update
-    - apt-get install -y build-essential libglpk40 libcurl4-gnutls-dev libxml2-dev libsodium-dev libsecret-1-dev libfontconfig1-dev libssl-dev libxt6 libpq-dev imagemagick
+    - apt-get install -y build-essential libglpk40 libcurl4-gnutls-dev libxml2-dev libsodium-dev libsecret-1-dev libfontconfig1-dev libssl-dev libxt6 libpq-dev imagemagick ghostscript software-properties-common
+    - add-apt-repository ppa:saiarcot895/chromium-beta
+    - apt update
+    - apt install -y chromium-browser
+    - chromium-browser --no-sandbox --headless --disable-gpu --run-all-compositor-stages-before-draw --no-pdf-header-footer --print-to-pdf https://www.ids-mannheim.de/
     - locale-gen de_DE.utf8 en_GB.utf8 en_US.utf8
 
     - end_section install_linux_packages
@@ -44,5 +48,6 @@
     - R_CACHE_ROOTPATH=./cache R -f ./R/icc_stats.R
     - R_CACHE_ROOTPATH=./cache R -e "require(rmarkdown); render('R/report.Rmd', output_format='html_document', output_dir='target')"
     - R_CACHE_ROOTPATH=./cache R -e "require(rmarkdown); render('R/poster.Rmd', output_format='posterdown::posterdown_ids', output_dir='target')"
+    - ./ci/html2pdf target/poster.html target/poster.pdf 1
     - end_section render
 
diff --git a/Readme.md b/Readme.md
index 1335c17..8335e22 100644
--- a/Readme.md
+++ b/Readme.md
@@ -12,6 +12,8 @@
 
 A generated report can be found [here](https://korap.ids-mannheim.de/instance/icc/iclc10/index.html).
 
+The latest generated poster can be found [here](![POS proportions](https://gitlab.ids-mannheim.de/ICC/2023-07-20-ICC-ICLC10/-/jobs/artifacts/master/raw/target/poster.pdf?job=build-job)).
+
 ## Some artifacts
 
 ### Tokens per ICC genre
diff --git a/ci/html2pdf b/ci/html2pdf
new file mode 100755
index 0000000..1744ebf
--- /dev/null
+++ b/ci/html2pdf
@@ -0,0 +1,11 @@
+#!/bin/sh -eu
+in=$1 out=$2 page0=${3:-} page1=${4:-$page0}
+${CHROME:-chromium-browser} --no-sandbox --headless --disable-gpu \
+    --run-all-compositor-stages-before-draw --print-to-pdf-no-header \
+     --no-pdf-header-footer --print-to-pdf="$out" "$in"
+GS_ARGS=
+if [ -n "$page0" ]; then
+        GS_ARGS="-dFirstPage=$page0 -dLastPage=$page1"
+fi
+gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH $GS_ARGS -sOutputFile="$2.tmp" "$2"
+mv "$2.tmp" "$2"