我正在尝试在 centos 7 中运行带有 wkthmltopdf 0.12.4 的 docker 容器。我们只想支持“Arial”、“Times New Roman”和“Courier New”,并且确实想处理msttcorefonts
包。所以解放字体包已经足够接近了。但是,似乎我需要添加其他配置才能正确匹配。
在容器内,字体似乎符合我的预期
[root@bafe67a1d200 /]# fc-match 'Arial'
LiberationSans-Regular.ttf: "Liberation Sans" "Regular"
[root@bafe67a1d200 /]# fc-match 'Times'
LiberationSerif-Regular.ttf: "Liberation Serif" "Regular"
[root@bafe67a1d200 /]# fc-match 'Courier New'
LiberationMono-Regular.ttf: "Liberation Mono" "Regular"
但是当我尝试使用 wkhtmltopdf 转换来自 ckEditor 的以下内容时
<span style="font-family:'arial' , 'helvetica' , sans-serif">
This is Arial
</span>
<span style="font-family:Times New Roman,Times,serif;">
This is Times
</span>
<span style="font-family:Courier New,Courier,monospace;">
This is Courier New
</span>
他们都在 pdf 中以 LiberationSans 的形式出现
但是,如果手动将字体系列更改为以下。它按预期工作
<span style="font-family:'Liberation Sans'">This is Arial</span>
<span style="font-family:'Liberation Serif">This is Times</span>
<span style="font-family:'Liberation Mono">This is Courier New</span>
这让我相信我可能需要在 fontconfig 中添加一些配置以匹配行为
Here is my docker file
FROM dockerhub.com/jetty
# must be root to install things
USER root
# install wkhtmlpdf and its dependencies
RUN yum install -y libXrender fontconfig libXext && \
wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz -O wkhtmltopdf.tar.xz && \
tar -Jxf wkhtmltopdf.tar.xz && \
cp -r wkhtmltox/bin/* /usr/local/bin/ && cp -r wkhtmltox/lib/* /usr/lib/ && cp -r wkhtmltox/include/* /usr/include/ && \
rm wkhtmltopdf.tar.xz && \
# install supported fonts
# - liberation-sans-fonts: Airal
# - liberation-serif-fonts: Times New Roman
# - liberation-mono-fonts: Courier New
yum install -y liberation-fonts-common liberation-serif-fonts liberation-sans-fonts liberation-mono-fonts
# copy the war into jetty to be deployed
COPY maven /opt/jetty-base