Skip to content

Commit e940420

Browse files
committed
Fix PDF generation by reverting to Prince 11
Closes #255. Additionally, this uses a custom temporary directory for pdfsizeopt, as I was getting permission errors (likely due to Docker/Windows/WSL interactions) when testing this locally with the default temporary directory being the output directory.
1 parent c394e21 commit e940420

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

ci-build/Dockerfile

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ FROM debian:stable
55
RUN apt-get update && \
66
apt-get install --yes --no-install-recommends \
77
ca-certificates curl rsync git \
8+
libfontconfig1 libgomp1 libxml2 \
89
default-jre \
910
python3 python3-pip \
1011
fonts-dejavu fonts-droid-fallback fonts-liberation fonts-symbola fonts-unfonts-core
1112

1213
# Dependency lines above are:
1314
# - General
15+
# - Prince
1416
# - validator
1517
# - Highlighter
1618
# - fonts, for when Prince renders to PDF
@@ -31,11 +33,16 @@ RUN chmod a+rwx /bin/pdfsizeopt/pdfsizeopt
3133
ADD https://github.com/validator/validator/releases/download/jar/vnu.jar /whatwg/
3234

3335
# Trying to copy Prince from its DockerHub container like the others does not work; it has too many
34-
# shared library dependencies. So we get the .deb file from the source:
35-
ADD https://www.princexml.com/download/prince_13.5-1_debian10_amd64.deb .
36-
RUN apt-get install --yes --no-install-recommends ./prince_13.5-1_debian10_amd64.deb && \
37-
rm prince_13.5-1_debian10_amd64.deb && \
38-
echo '@font-face { font-family: serif; src: local("Symbola") }' >> /usr/lib/prince/style/fonts.css
36+
# shared library dependencies. Additionally, Prince 12 and 13 have bad interactions with pdfsizeopt
37+
# (https://github.com/pts/pdfsizeopt/issues/145, https://github.com/whatwg/html-build/issues/255),
38+
# and Prince 11's .deb file only works with older version of Debian. So, we do it this way (plus the
39+
# manual dependency installations in the apt-get section above).
40+
ADD https://www.princexml.com/download/prince-11.3-linux-generic-x86_64.tar.gz /whatwg/prince.tar.gz
41+
RUN cd /whatwg && \
42+
tar xzf prince.tar.gz && \
43+
echo /whatwg/prince | /whatwg/prince-11.3-linux-generic-x86_64/install.sh && \
44+
echo '@font-face { font-family: serif; src: local("Symbola") }' >> /whatwg/prince/lib/prince/style/fonts.css && \
45+
rm -rf /whatwg/prince.tar.gz /whatwg/prince-11.3-linux-generic-x86_64
3946

4047
ADD . /whatwg/html-build
4148

ci-build/inside-container.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ echo ""
2525
echo ""
2626
echo "Building PDF..."
2727
PDF_TMP="$(mktemp --suffix=.pdf)"
28-
prince --verbose --output "$PDF_TMP" "http://0.0.0.0:$PDF_SERVE_PORT/"
28+
PATH=/whatwg/prince/bin:$PATH prince --verbose --output "$PDF_TMP" "http://0.0.0.0:$PDF_SERVE_PORT/"
2929

3030
echo ""
3131
echo "Optimizing PDF..."
32-
PATH=/bin/pdfsizeopt:$PATH pdfsizeopt --v=30 "$PDF_TMP" "$HTML_OUTPUT/print.pdf"
32+
TMP_DIR=$(mktemp -d)
33+
PATH=/bin/pdfsizeopt:$PATH pdfsizeopt --v=30 "--tmp-dir=$TMP_DIR" "$PDF_TMP" "$HTML_OUTPUT/print.pdf"

0 commit comments

Comments
 (0)