如何一步步让DOMPDF支持unicode字体?

发布于 2024-12-28 21:31:14 字数 193 浏览 4 评论 0原文

我使用了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

纵情客 2025-01-04 21:31:14
  1. 启用 mbstring 扩展
  2. .ttf 使用支持您给定语言的字符的格式
  3. 为 DOMPDF 生成 .afm 文件:
    1. 使用命令行,cd进入包含load_font.php的目录,然后运行php load_font.php FontName /path/to/font.ttf
    2. 使用在线工具填写表格并下载它为您提供的 zip 文件。将此 zip 中的文件复制到 dompdf/lib/fonts 中。如果您之前已完成此操作,请将相关行添加到 dompdf_font_family_cache,否则只需将 dompdf_font_family_cache.sample 重命名为 dompdf_font_family_cache
  4. 启用 DOMPDF 的 Unicode模式,通过确保行

    define("DOMPDF_UNICODE_ENABLED", true);
    

    dompdf_config.inc.php中设置。如果它读取的是 false 而不是 true,请更改它。

  1. Enable the mbstring extension
  2. Find a font in .ttf format with characters that support your given language
  3. Generate a .afm file for DOMPDF:
    1. Using the command line, cd into the directory which contains load_font.php, then run php load_font.php FontName /path/to/font.ttf
    2. Using the online tool, fill out the form and download the zip it gives you. Copy the files from this zip into dompdf/lib/fonts. If you've done this before, add relevant lines to dompdf_font_family_cache, otherwise simply rename the dompdf_font_family_cache.sample to dompdf_font_family_cache
  4. Enable DOMPDF's Unicode mode, by making sure the line

    define("DOMPDF_UNICODE_ENABLED", true);
    

    is set in dompdf_config.inc.php. If it reads false instead of true, change that.

清浅ˋ旧时光 2025-01-04 21:31:14

为此,有一个 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.

抠脚大汉 2025-01-04 21:31:14

从版本 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.

悲念泪 2025-01-04 21:31:14

下载load_font.php并放置在你的项目根目录中

查看load_font.php

添加$fontDir = "storage/fonts";

这将显示添加字体的位置。

下载您的字体,例如: PREETI 并将其放置在您的项目根

目录中,在命令行 php load_font.php PREETI PREETI.ttf 中运行,

然后您的字体将被安装到 storage/fonts 目录

现在转到 pdf 文件并添加

<style>
    body {
        font-family: PREETI;
        color: #1c2221;
    }
</style>

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 directory

now go to the pdf file and add

<style>
    body {
        font-family: PREETI;
        color: #1c2221;
    }
</style>
旧故 2025-01-04 21:31:14

尝试使用推荐的 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文