Last active
August 29, 2020 05:47
-
-
Save akihiromukae/288b163d538d45a197b3f1b54ef385e8 to your computer and use it in GitHub Desktop.
wkhtmltopdfをAlpine linuxに入れてPDF出力する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
まずはここのDockerfileを参考にするだけだとxvfbが足りなくて動かないので16行目に追加し、 | |
https://github.com/LoicMahieu/alpine-wkhtmltopdf/blob/master/Dockerfile | |
以下のものも参考にdbusはdbusパッケージにあるdbus-genuuidを実行しておかないと、xvfb実行時にエラーになるので35行目に追加。 | |
http://kernhack.hatenablog.com/entry/2016/05/28/101626 | |
日本語ならIPAFontも入れると良いが、ググればすぐにでてくるので割愛。 | |
これだけだと、CSSが効かない状態でPDF出力されるので別途対応が必要。ヘッドレスブラウザが必要? | |
FROM alpine:3.3 | |
RUN apk add --no-cache \ | |
xvfb \ | |
# Additionnal dependencies for better rendering | |
ttf-freefont \ | |
fontconfig \ | |
dbus \ | |
xvfb \ | |
&& \ | |
# Install wkhtmltopdf from `testing` repository | |
apk add qt5-qtbase-dev \ | |
wkhtmltopdf \ | |
--no-cache \ | |
--repository http://dl-3.alpinelinux.org/alpine/edge/testing/ \ | |
--allow-untrusted \ | |
&& \ | |
# Wrapper for xvfb | |
mv /usr/bin/wkhtmltopdf /usr/bin/wkhtmltopdf-origin && \ | |
echo $'#!/usr/bin/env sh\n\ | |
Xvfb :0 -screen 0 1024x768x24 -ac +extension GLX +render -noreset & \n\ | |
DISPLAY=:0.0 wkhtmltopdf-origin $@ \n\ | |
killall Xvfb\ | |
' > /usr/bin/wkhtmltopdf && \ | |
chmod +x /usr/bin/wkhtmltopdf \ | |
dbus-genuuid |
Author
akihiromukae
commented
Jan 18, 2018
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment