2

I am trying run a docker container with wkthmltopdf 0.12.4 in centos 7. We only want to support "Arial", "Times New Roman" and "Courier New" and do want to deal with msttcorefonts package. So the liberation fonts packages is close enough. However, It seems like I need to add additional config for it to match correctly.

Inside container it seems like the font is matching as I expected

[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"

But when I tried to convert the following coming from ckEditor with wkhtmltopdf

<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>

They all come back as LiberationSans in the pdf

However if manually change the font family to the following. It works as expected

<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>

That leads me to believe I might need to add some config in the fontconfig to match the behavior

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
AirWick219
  • 894
  • 8
  • 27
  • I'm not sure if i understand correctly but if you want to add extra fonts to the editor you need to add them to CSS (contents.css or main page css file fi you are using inline editor) using `@font-face` and then to use them in the editor, you need to set https://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-font_names. – j.swiderski Oct 02 '17 at 12:58
  • This is not about adding extra fonts to CKEDITOR. So we have a separate docker container to covert html to pdf via wkhtmltopdf. Our document in ckeditor adds the correct ```font-family``` in the html. But inside the docker container, it appears that it doesn't know what 'Time New Roman' or other fonts from ```msttcorefonts``` is. So the mapping is off and everything just got rendered to a default ```Liberation Sans``` and ignore all the other fonts. – AirWick219 Oct 02 '17 at 15:23
  • 1
    @AirWick219 Did you find any solution for the above problem, I have been facing the same issue! – Jestino Sam Jun 12 '21 at 12:56

0 Answers0