什么是 Debian 的 urw-fonts 等价物(wkhtmltopdf 中的 utf-8 需要)? [英] What is the Debian equivalent of urw-fonts (needed for utf-8 in wkhtmltopdf)?
问题描述
我正在尝试使用 wkhtmltopdf 将包含多种语言(utf-8 编码)文本的 html 文档转换为 pdf,并遇到了此处描述的确切问题:
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:
最流行的答案是安装 urw-fonts,这似乎对许多有此问题的人有用.但是当我在 Debian apt 存储库中搜索这个包时,它什么也没找到.有人建议安装 gsfonts-x11,但这并没有解决问题.
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.
我的问题是:
是否有类似/等效的 Debian 字体包可以被 wkhtmltopdf 用来正确渲染 utf-8 字体?
Is there a similar/equivalent Debian font package that can be used by wkhtmltopdf to correctly render utf-8 fonts?
谢谢!
推荐答案
在wkhtmltopdf中获取其他语言渲染:
Getting other languages rendering in wkhtmltopdf:
- 创建了一个文件夹:/path/to/downloaded/fonts
- 创建 fonts.conf(见下文)
/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>
将 Google 的 Noto 字体下载到/var/task/fonts.对于您需要的每种语言,您可以下载其相关的语言 ttf 文件.
downloaded Google's Noto fonts into /var/task/fonts. For each language you need, you can download its associated language ttf files.
设置您的 ENV 变量:FONT_CONFIG_PATH=/path/to/downloaded/fonts/
和 FONTCONFIG_FILE=/path/to/downloaded/fonts/fonts.conf
Set your ENV variables:
FONT_CONFIG_PATH=/path/to/downloaded/fonts/
and FONTCONFIG_FILE=/path/to/downloaded/fonts/fonts.conf
在目标HTML文件中,在文档头部设置meta标签:
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>
您可能会发现需要添加额外的字体,但在Google Noto 网站.我使用了所有 *-regular.ttf 文件来保持容器更小.
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.
如果你恰好在 AWS/amazonlinux2 中这样做,你还需要设置:导出 LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/wkhtmltopdf;
您可以使用以下命令确认库已正确映射:ldd/path/to/wkhtmltopdf
您的结果应如下所示:
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)
这篇关于什么是 Debian 的 urw-fonts 等价物(wkhtmltopdf 中的 utf-8 需要)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!