在DOMPDF中使用日语字符?

时间:2017-10-09 08:23:58

标签: dompdf

我正在尝试使用DOMpdf创建我的PDF,以便正确使用日文字符。我用法语等工作得很好,但是日文字符没有显示(只是得到???)

以下是HTML页面的外观:

enter image description here

...但PDF出现为:

enter image description here

我正在使用的代码非常简单:

<?php

// include autoloader
require_once '/path/to/admin/invoices/autoload.inc.php';

define("DOMPDF_ENABLE_REMOTE", true);
define("DOMPDF_UNICODE_ENABLED", true);

// reference the Dompdf namespace
use Dompdf\Dompdf;

$order_id = $argv[1];

$content = file_get_contents("/path/to/admin/invoices/html_versions/$order_id.html");

// // instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->loadHtml($content);

 // Render the HTML as PDF
$dompdf->render();

// Output the generated PDF to Browser
$dompdf->stream();

?>

从我所看到的,它需要专门针对日语的字体。

  1. 什么字体可以使用?
  2. 我可以将它与普通字体一起运行吗?即我仍然希望能够展示像íóéeta
  3. 这样的东西

    更新:我越来越近了!

    我已下载Cyber​​CJK TTF字体(如此处所示:https://github.com/dompdf/dompdf/issues/938

    然后我将CSS调整为:

    @font-face {
        font-family: CyberCJK;
        font-style: normal;
        font-weight: normal;
        src: url("https://example.com/cgi-bin/admin/invoices/lib/fonts/DejaVuSerif.ttf") format("truetype");
    }
    * {
      font-family: 'CyberCJK', sans-serif;
    }
    
    @page { margin: 0px; } body { margin: 0px; }
    
    html { font-size: 14px/1; font-family: 'CyberCJK', sans-serif; overflow: auto; }
    

    ..现在我得到了部分角色:

    enter image description here

    我还测试了上传我的HTML页面:http://www.htm2pdf.co.uk,它完美地以PDF格式出现,并且也只有64kb,而使用DOMPdf则为13mb +。必须要有东西!

    我真的不知道还有什么可以尝试:/

0 个答案:

没有答案