Saturday, June 27, 2020

Wkhtmltopdf Letter spacing issue (Bad Kerning)

When we are using smaller font in the document and trying convert to PDF the letter spacing is completely broken.

It will too visible when we use Arial font. We tried lot of way, finally we found a solution by

By creating a 10-wkhtmltopdf.conf inside /etc/fonts/conf.d/ with following content

<?xml version='1.0'?>

<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>

<fontconfig>

 <match target="font">

  <edit mode="assign" name="rgba">

   <const>rgb</const>

  </edit>

 </match>

 <match target="font">

  <edit mode="assign" name="hinting">

   <bool>true</bool>

  </edit>

 </match>

 <match target="font">

  <edit mode="assign" name="hintstyle">

   <const>hintslight</const>

  </edit>

 </match>

 <match target="font">

  <edit mode="assign" name="antialias">

   <bool>true</bool>

  </edit>

 </match>

  <match target="font">

    <edit mode="assign" name="lcdfilter">

      <const>lcddefault</const>

    </edit>

  </match>

</fontconfig>

Following link helped us to resolve this issue

https://html.developreference.com/article/17386238/letter-spacing+is+too+large+with+wkhtmltopdf

https://github.com/kisenka/docker-kotlin-website/blob/master/scripts/10-wkhtmltopdf.conf

No comments:

Post a Comment