我正在尝试使用DOMpdf创建我的PDF,以便正确使用日文字符。我用法语等工作得很好,但是日文字符没有显示(只是得到???)
以下是HTML页面的外观:
...但PDF出现为:
我正在使用的代码非常简单:
<?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();
?>
从我所看到的,它需要专门针对日语的字体。
更新:我越来越近了!
我已下载CyberCJK 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; }
..现在我得到了部分角色:
我还测试了上传我的HTML页面:http://www.htm2pdf.co.uk,它完美地以PDF格式出现,并且也只有64kb,而使用DOMPdf则为13mb +。必须要有东西!
我真的不知道还有什么可以尝试:/