I'm trying to convert an html document with text in multiple languages (utf-8 encoding) to pdf using wkhtmltopdf, and ran into the exact issue described here:
Squared characters issue on wkhtmltopdf
The most popular answers there are to install urw-fonts, which seems to have worked for many people with this issue. But when I search for this package in the Debian apt repository, it doesn't find anything. Someone suggested installing gsfonts-x11, but that didn't fix the issue.
My question is:
Is there a similar/equivalent Debian font package that can be used by wkhtmltopdf to correctly render utf-8 fonts?
Thanks!
Getting other languages rendering in wkhtmltopdf:
/path/to/downloaded/fonts/fonts.conf
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<dir>/path/to/downloaded/fonts/</dir>
<cachedir>/tmp/fonts-cache/</cachedir>
<config></config>
</fontconfig>
downloaded Google's Noto fonts into /var/task/fonts. For each language you need, you can download its associated language ttf files.
Set your ENV variables:
FONT_CONFIG_PATH=/path/to/downloaded/fonts/
and FONTCONFIG_FILE=/path/to/downloaded/fonts/fonts.conf
In the target HTML file, set the meta tag in the head of the document:
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
You may find that you need to add additional fonts, but they are found on the the Google Noto Site. I used all the *-regular.ttf files to keep my container smaller.
If you happen to be doing this in AWS / amazonlinux2, you also need to set:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/wkhtmltopdf;
You can confirm that the libaries are mapped correctly with:
ldd /path/to/wkhtmltopdf
Your result should look like this:
linux-vdso.so.1 (0x00007ffc7f5cf000)
libXrender.so.1 => /var/task/lib/libXrender.so.1 (0x00007f1ea6db1000)
libfontconfig.so.1 => /var/task/lib/libfontconfig.so.1 (0x00007f1ea6b74000)
libfreetype.so.6 => /var/task/lib/libfreetype.so.6 (0x00007f1ea68d0000)
libXext.so.6 => /var/task/lib/libXext.so.6 (0x00007f1ea66be000)
libX11.so.6 => /var/task/lib/libX11.so.6 (0x00007f1ea6380000)
libz.so.1 => /lib64/libz.so.1 (0x00007f1ea616b000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f1ea5f67000)
librt.so.1 => /lib64/librt.so.1 (0x00007f1ea5d5f000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f1ea5b41000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f1ea57bf000)
libm.so.6 => /lib64/libm.so.6 (0x00007f1ea547f000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f1ea5269000)
libc.so.6 => /lib64/libc.so.6 (0x00007f1ea4ebe000)
/lib64/ld-linux-x86-64.so.2 (0x00007f1ea6fbb000)
libexpat.so.1 => /var/task/lib/libexpat.so.1 (0x00007f1ea4c8c000)
libxcb.so.1 => /var/task/lib/libxcb.so.1 (0x00007f1ea4a64000)
libXau.so.6 => /var/task/lib/libXau.so.6 (0x00007f1ea4860000)
linux-vdso.so.1 (0x00007ffce59b0000)
If the path is wrong, it'll look like this:
libXrender.so.1 => not found
libfontconfig.so.1 => not found
libfreetype.so.6 => not found
libXext.so.6 => not found
libX11.so.6 => not found
libz.so.1 => /lib64/libz.so.1 (0x00007f2f1fed9000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f2f1fcd5000)
librt.so.1 => /lib64/librt.so.1 (0x00007f2f1facd000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f2f1f8af000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f2f1f52d000)
libm.so.6 => /lib64/libm.so.6 (0x00007f2f1f1ed000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f2f1efd7000)
libc.so.6 => /lib64/libc.so.6 (0x00007f2f1ec2c000)
/lib64/ld-linux-x86-64.so.2 (0x00007f2f200ee000)