带有西里尔字符的DOMPDF问题

Vla*_*ili 10 php pdf pdf-generation dompdf

我正在使用DOMPDF库以PDF格式创建发票.本文档可以是法语,俄语或英语,但我在打印俄语字符时遇到问题.

首先,我尝试使用UTF-8编码并将meta标记放在要转换的HTML页面的头部:

<meta http-equiv ="Content-Type"content ="text/html; charset = utf-8"/>

但那没用.

然后我metaBODY标签中插入了这个标签,它帮助解决了法语字符的问题.

但是俄罗斯人物仍然不起作用.我也尝试将俄语字符转换为HTML实体,但这也不起作用.

我使用R&OS CPDF类,而不是PDFLib作为后端.

有人可以帮忙吗?

And*_*nko 8

在接受的答案链接被破坏,它包含旧版本的DOMPDF.

要在DOMPDF 0.6中使用unicode符号,您有两种选择:使用现有字体或创建自己的字体.

  • 使用现有字体(适用于DOMPDF 0.6):

    1. 下载档案和摘录.
    2. 复制dompdf fonts文件夹中的解压缩文件/dompdf/lib/fonts/.
    3. dompdf_font_family_cache.dist.php使用代码段1进行编辑.
    4. 在CSS中使用font-family: times;.

小片1:

/* ... */
'times' => array (
    'normal' => DOMPDF_FONT_DIR . 'times',
    'bold' => DOMPDF_FONT_DIR . 'timesbd',
    'italic' => DOMPDF_FONT_DIR . 'timesi',
    'bold_italic' => DOMPDF_FONT_DIR . 'timesbi'
),
'times-roman' => array (
    'normal' => DOMPDF_FONT_DIR . 'times',
    'bold' => DOMPDF_FONT_DIR . 'timesbd',
    'italic' => DOMPDF_FONT_DIR . 'timesi',
    'bold_italic' => DOMPDF_FONT_DIR . 'timesbi'
),
/* ... */
Run Code Online (Sandbox Code Playgroud)
  • 如果你想使用自己的TTF字体(比方说Arial.ttf):

    1. 跑:ttf2afm -o Arial.afm Arial.ttf.(我在Ubuntu做过.)
    2. 跑:ttf2ufm -a -F Arial.ttf.(我在Windows中使用UFPDF的 exe 做过,但我想你可以使用/dompdf/lib/ttf2ufm/bin/ttf2ufm.exe.)
    3. 复制Arial.*文件/dompdf/lib/fonts/.
    4. 添加到dompdf_font_family_cache.dist.php代码段2.
    5. 在CSS中使用font-family: arial;.

摘录2:

/* ... */
'arial' => array (
    'normal' => DOMPDF_FONT_DIR . 'Arial',
    'bold' => DOMPDF_FONT_DIR . 'Arial',
    'italic' => DOMPDF_FONT_DIR . 'Arial',
    'bold_italic' => DOMPDF_FONT_DIR . 'Arial'
)
/* ... */
Run Code Online (Sandbox Code Playgroud)


nfo*_*ort 8

如果您使用DejaVu字体,您可以看到西里尔字符

DejaVu TrueType字体已预先安装,默认情况下为dompdf提供了良好的Unicode字符覆盖率.要使用DejaVu字体,请参考样式表中的字体,例如body {font-family:DejaVu Sans; (对于DejaVu Sans).

DOMPDF包括DejaVu字体是默认的

    $html = "<html><head><style>body { font-family: DejaVu Sans }</style>".
        "<body>? ??? ? ?????????</body>".
        "</head></html>";

    $dompdf = new \DOMPDF();
    $dompdf->load_html($html);
    $dompdf->render();
    echo file_put_contents('cyrillic.pdf', $dompdf->output());
Run Code Online (Sandbox Code Playgroud)

您还可以在dompdf_config.inc.php中默认为字体设置更改def

def("DOMPDF_DEFAULT_FONT", "DejaVu Sans");
Run Code Online (Sandbox Code Playgroud)


Art*_*pov 7

问题是字体默认使用dompdf(也就是说它没有所有的unicode字符,现在已超过5000).通常arialuni.ttf就是你所需要的.你可以在http://chernev.ru/dompdf.rar下载本地化的俄语版本{已断开链接}

更新链接:https://code.google.com/p/ipwn/downloads/detail?name = arialuni.ttf