如何一步步让DOMPDF支持unicode字体?
我使用了 DOMPDF 库,现在我对 unicode 语言的内容有问题。我找到了这个dompdf 帮助 但我不明白这一点。谁能详细说明一下吗? 谢谢
I used DOMPDF library and now I have problem with content with unicode language. and I found this one dompdf help
but I don't understand about this. can anyone tell the detail of this?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
.ttf
使用支持您给定语言的字符的格式.afm
文件:cd
进入包含load_font.php
的目录,然后运行php load_font.php FontName /path/to/font.ttf
dompdf/lib/fonts
中。如果您之前已完成此操作,请将相关行添加到dompdf_font_family_cache
,否则只需将dompdf_font_family_cache.sample
重命名为dompdf_font_family_cache
启用 DOMPDF 的 Unicode模式,通过确保行
在
dompdf_config.inc.php
中设置。如果它读取的是false
而不是true
,请更改它。.ttf
format with characters that support your given language.afm
file for DOMPDF:cd
into the directory which containsload_font.php
, then runphp load_font.php FontName /path/to/font.ttf
dompdf/lib/fonts
. If you've done this before, add relevant lines todompdf_font_family_cache
, otherwise simply rename thedompdf_font_family_cache.sample
todompdf_font_family_cache
Enable DOMPDF's Unicode mode, by making sure the line
is set in
dompdf_config.inc.php
. If it readsfalse
instead oftrue
, change that.为此,有一个 wiki 页面。
即将发布的下一个测试版(0.6 beta 3)有一个不需要命令行(也不需要任何编译)的字体安装程序。
您已经可以通过查看 SVN 主干来使用它。此测试版还支持
@font-face
。There is a wiki page for this.
The next beta (0.6 beta 3), to be released soon, has a font installer that doesn't require the command line (neither any compilation).
You already can use it by checking out the SVN trunk. This beta also supports
@font-face
.从版本 0.7 开始,dompdf 支持并默认启用 unicode。 (因此不需要配置)。
但并非所有 dompdf 字体都支持 unicode。我成功地使用了
font-family: DejaVu Sans
。要安装自定义字体或了解更多信息,您可以阅读官方 unicode 操作方法。
As of version 0.7, dompdf supports and has unicode enabled by default. (therefore there is no need for configuration).
Not all dompdf fonts support unicode though. I used
font-family: DejaVu Sans
with success.To install a custom font or learn more about it you can read the official unicode how to.
下载load_font.php并放置在你的项目根目录中
查看
load_font.php
添加
$fontDir = "storage/fonts";
这将显示添加字体的位置。
下载您的字体,例如: PREETI 并将其放置在您的项目根
目录中,在命令行
php load_font.php PREETI PREETI.ttf
中运行,然后您的字体将被安装到
storage/fonts
目录现在转到 pdf 文件并添加
Download load_font.php and place in ur project root
View
load_font.php
add
$fontDir = "storage/fonts";
This will show where the fonts are added.
download your font at eg: PREETI and place at your project root
run in command line
php load_font.php PREETI PREETI.ttf
then you font will be installed to
storage/fonts
directorynow go to the pdf file and add
尝试使用推荐的 DOMPDF 方法 操作您的代码
这是在 DOMPDF 中启用 Unicode 支持的指南
为了确保最大的兼容性,您应该遵循以下所有步骤。点击查看更多详细信息。
<代码>
确保 MBString PHP 扩展已启用
安装 dompdf 0.6.0 或更高版本
配置 dompdf 以支持 Unicode
将支持您的字符的字体加载到 dompdf 中
创建兼容的 HTML 文档
请参阅链接了解更多信息
try to manipulate your code using this recommended DOMPDF method
it's a A guide to enabling Unicode support in DOMPDF
To ensure maximum compatibility you should follow all of the following steps. Click through for additional details.
Ensure the MBString PHP extension is enabled
Install dompdf 0.6.0 or greater
Configure dompdf for Unicode support
Load a font supporting your characters into dompdf
Create a compatible HTML document
see the link for more information