Hello i want to convert html to pdf using dompdf, my HTML has Chinese text. In HTML view the Chinese text show very well, but when I convert to pdf the Chinese text only show square.
This is my code
$html = $this->load->view('view_view', $data, TRUE);
//echo $html;
require("assets/dompdf1/autoload.inc.php");
define("DOMPDF_UNICODE_ENABLED", true);
$options = new Options();
$options->set('defaultFont', 'DejaVu Sans');
$dompdf = new Dompdf($options);
$html = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8');
$dompdf->loadHtml($html);
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
$dompdf->stream("View.pdf", array("Attachment" => false));
exit(0);
I already set the font face in the HTML
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
@page {
margin-top: 0.3cm;
margin-bottom: 0cm;
}
@font-face {
font-family: 'NotoSansCJK';
src: url('assets/dompdf1/lib/fonts/NotoSansCJKtc-Regular.ttf') format('truetype');
}
body {
font-family: 'NotoSansCJK', DejaVu Sans, sans-serif;
}
</style>
Can someone help me, I already searching anywhere but still don’t find the solution
I use dompdf ver 0.8.0
EDIT: I follow chams by adding the line
$options = new Options();
$options->set('defaultFont', 'DejaVu Sans');
$dompdf = new Dompdf($options);
and the square is gone, I don’t know what is wrong
Update
EDIT: I just update the font, I’m using kai bold font, the square is coming back the error
EDIT: I just update the font again, I’m using NotoSansCJKtc-Regular, and still got the square.
2
Answers
I try many solution but still the chinese text is not shown anyone can help me?
Make sure to a font that support Chinese characters which Dompdf by default don’t support.
EDIT: