dompdf不显示一些拉丁字符 [英] dompdf not displaying some of latin characters

查看:82
本文介绍了dompdf不显示一些拉丁字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是最新的稳定的0.6 dompdf版本,但是我无法显示一些拉丁字符,我看到该文档现在已经可用。

I am using latest stable 0.6 dompdf version but I am unable to display some latin characters, I see that documentation is for now incomeplete.

到目前为止,我正在尝试要使用Open Sans字体,我什至将其转换为afm格式,但仍使用?显示某些显示。而不是我们的拉丁字符č,ć,đ,ž。

So far I am trying to use Open Sans font, I have even converted it to afm format, but still some display are displayed with ? instead of our latin characters 'č, ć, đ, ž'.

字体以ttf格式下载,并且字体定义如下添加到dompdf_font_family_cache.dist.php文件中:

Font is downloaded as ttf, and font definition is added to dompdf_font_family_cache.dist.php file as follows:

'open sans' => 
  array (
    'normal' => $rootDir . '/lib/fonts/OpenSans',
  ),

将html内容输出到浏览器可使这些字符正常显示。是否有任何官方解决方案,是因为缺少load_font.php还是应将其更新为0.7-beta并改用@ font-face?

Outputing html contents to browser renders these characters fine. Is there any official solution, because load_font.php is missing or should update to 0.7-beta and use @font-face instead?

推荐答案

字符编码

PDF文档的默认编码为Windows ANSI (1)。此编码提供了有限的字符集支持,不包括问题中指定的字符(č,ć,đ,ž)。因此,在对文本进行技术上的拉丁编码后,支持这些字符的特定编码( ISO-8859 -5 )与PDF文档( Windows)中提供的默认值不同。 -1252 ,又名Windows ANSI,几乎是 ISO-8859-1 )。

The default encoding of a PDF document is Windows ANSI (1). This encoding provides limited character set support that does not include the characters specified in the question (č, ć, đ, ž). So while the text is technically latin-encoded the specific encoding that supports those characters (ISO-8859-5) is not the same as the default one provided provided in PDF documents (Windows-1252, aka Windows ANSI, which is pretty much ISO-8859-1).

字体指标

出现字符编码问题请记住,您通过加载字体,采取了正确的方法来增加对字符的支持。但是,这样做的方法不会获得预期的结果。 dompdf(在使用CPDF后端时)利用字体指标来确定如何布置文档文本。字体指标有两种形式,AFM(Adobe字体指标)和UFM(Unicode字体指标)。这两种形式对应于dompdf支持的两种可能的编码:Windows ANSI和Unicode。您的字体指标采用AFM格式这一事实向dompdf表示该字体已编码为Windows ANSI。

With the character encoding issue in mind you took the right approach to add support for your characters by loading a font. The means by which you've done it, however, will not get you the expected results. dompdf (when using the CPDF backend) utilizes font metrics to determine how to lay out the text of a document. The font metrics come in two forms, AFM (Adobe Font Metrics) and UFM (Unicode Font Metrics). These two forms correspond to the two possible encodings supported by dompdf, Windows ANSI and Unicode. The fact that your font metrics are in AFM format indicates to dompdf that the font is encoded as Windows ANSI.

加载字体

虽然您可以修改dompdf_font_family_cache.dist.php文件,但不建议这样做。由于该文件是分发的一部分,因此您执行的所有更新都可能会覆盖该文件。使用任何受支持的字体加载方法dompdf时,将创建一个名为dompdf_font_family_cache.php的文件,以存储自定义字体的名称/位置信息。如果要调整自定义字体信息,请在此文件中进行。此文件通常与与自定义字体关联的TTF和AFM文件一起存储(不一定存储在dompdf / lib / fonts目录中,具体取决于您的配置)。

While you can modify the dompdf_font_family_cache.dist.php file it is not recommended. Since that file is included as part of the distribution any updates you perform could over-write the file. When using any of the supported font-loading methods dompdf will create a file called dompdf_font_family_cache.php to store name/location information for your custom fonts. If you want to tweak your custom font information you would do so in this file. This file is typically stored alongside the TTF and AFM files associated with the custom fonts (not necessarily in the dompdf/lib/fonts directory ... depending on your configuration).

我建议您不要手动编辑dompdf_font_family_cache.php。如果没有其他原因,我会使用CSS @ font-face 规则来定义和加载字体。如果您倾向于使用命令行工具来预加载字体,则dompdf的0.6.x版本中仍包含load_font.php脚本(不确定为什么会这样)。如果要移至0.7.0,可以在 dompdf-utils中找到load_font.php脚本的更新版本。项目

I would recommend against manually editing dompdf_font_family_cache.php. Rather I would use the CSS @font-face rules to define and load fonts if for no other reason ease of use. If you're inclined to use a command line tool to pre-load your fonts the load_font.php script is still included in the 0.6.x releases of dompdf (not sure why you think otherwise). If you want to move to 0.7.0 you can find an updated version of the load_font.php script in the dompdf-utils project.

最后,如果您仍然遇到问题,可以随时尝试使用捆绑的DejaVu字体之一(从dompdf 0.6.0开始可用)。

Lastly, if you continue to have trouble you can always try using one of the bundled DejaVu fonts (available starting with dompdf 0.6.0).

(1)是的,是的,有一些可能的编码。但是在大多数情况下,您可以将Windows ANSI视为默认设置。

(1) OK, yes, there are a few possible encodings. But for the most part you can consider Windows ANSI the default.

这篇关于dompdf不显示一些拉丁字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆