1、使用docker拉取镜像
docker pull ghcr.io/surnet/alpine-wkhtmltopdf:3.20.2-0.12.6-full
2、在原有镜像当中,新增中文字体兼容
root:~# cat DockerfileFROM ghcr.io/surnet/alpine-wkhtmltopdf:3.20.2-0.12.6-full# 添加中文字体(Google 官方可下载)RUN apk add --no-cache fontconfig wget \&& mkdir -p /usr/share/fonts/noto \&& wget -O /usr/share/fonts/noto/NotoSansSC-Regular.otf https://fonts.gstatic.com/ea/notosanssc/v1/NotoSansSC-Regular.otf \&& wget -O /usr/share/fonts/noto/NotoSansSC-Bold.otf https://fonts.gstatic.com/ea/notosanssc/v1/NotoSansSC-Bold.otf \&& fc-cache -f -v
3、新建镜像
docker build -t wkhtmlpdf-cn .
4、验证PDF转换
cat >/usr/local/bin/wk <<'EOF'#!/bin/bashdocker run --rm \--entrypoint "" \-v "$(pwd)":/data \-w /data \wkhtmlpdf-cn:latest \wkhtmltopdf \--enable-local-file-access \--encoding utf-8 \--load-error-handling ignore \"$@"EOFchmod +x /usr/local/bin/wk#测试,宿主机操作echo "<h1>中文测试:我爱中国</h1>" > test.htmlwk test.html test.pdf

