Skip to content

Instantly share code, notes, and snippets.

@shichi-at-nttr
Created May 24, 2020 01:38
Show Gist options
  • Save shichi-at-nttr/68550fb4c19c9737195a3f09cf5b1a9c to your computer and use it in GitHub Desktop.
Save shichi-at-nttr/68550fb4c19c9737195a3f09cf5b1a9c to your computer and use it in GitHub Desktop.
Alpine Linux 3.11 で wkhtmltopdf を動かし、日本語WebページをPDF化する
# -------------------------------------------------------------
# 日本語のWebページをPDF化する
# -------------------------------------------------------------
# ビルド: docker build -t alpine-wkhtmltopdf .
# 実行: docker run alpine-wkhtmltopdf https://www.goo.ne.jp - > test.pdf
# -------------------------------------------------------------
# ベースはこちら
# https://github.com/madnight/docker-alpine-wkhtmltopdf
FROM alpine:3.11
# コンテナのTimezoneをJSTにする (ログのタイムスタンプ用)
# http://kawaken.hateblo.jp/entry/2018/08/30/190954
RUN apk --no-cache add tzdata && \
cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
RUN apk add --update --no-cache \
libgcc libstdc++ libx11 glib libxrender libxext libintl \
ttf-dejavu ttf-droid ttf-freefont ttf-liberation ttf-ubuntu-font-family
# On alpine static compiled patched qt headless wkhtmltopdf (46.8 MB).
# Compilation took place in Travis CI with auto push to Docker Hub see
# BUILD_LOG env. Checksum is printed in line 13685.
COPY --from=madnight/alpine-wkhtmltopdf-builder:0.12.5-alpine3.10-606718795 \
/bin/wkhtmltopdf /bin/wkhtmltopdf
ENV BUILD_LOG=https://api.travis-ci.org/v3/job/606718795/log.txt
RUN [ "$(sha256sum /bin/wkhtmltopdf | awk '{ print $1 }')" == \
"$(wget -q -O - $BUILD_LOG | sed -n '13685p' | awk '{ print $1 }')" ]
# 日本語対応(IPAフォントのインストール)
# https://ipafont.ipa.go.jp/old/ipafont/download.html
RUN apk --no-cache add fontconfig \
&& cd \
&& wget https://ipafont.ipa.go.jp/IPAfont/ipagp00303.zip \
&& unzip ipagp00303.zip \
&& mkdir -p /usr/share/fonts/ipa \
&& cp ipagp00303/ipagp.ttf /usr/share/fonts/ipa \
&& fc-cache -fv
ENTRYPOINT ["wkhtmltopdf"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment