Home>Article>Backend Development> What to do if php dompdf Chinese garbled characters

What to do if php dompdf Chinese garbled characters

藏色散人
藏色散人 Original
2023-01-18 10:34:04 3442browse

php dompdf Chinese garbled solution: 1. Open the front-end file; 2. Set "@font-face" {font-family:ttt;src: url(/static/font/simkai.ttf)}" refers to the Chinese font; 3. Delete "dompdf_font_family_cache.php".

What to do if php dompdf Chinese garbled characters

##The operating environment of this tutorial: Windows 10 system, PHP version 8.1, DELL G3 computer

What should I do if dompdf has Chinese garbled characters?

php exports pdf, Solution to garbled Chinese fonts in dompdf (especially garbled characters caused by code migration)

dompdf\lib\fonts\dompdf_font_family_cache.php Remember that this file stores the cache generated by the font. If this file is overwritten during migration It will cause garbled code and it is difficult to find the error, believe me...

dompdf is a tool for exporting html to pdf from php. It is very easy to use. Except for a few css3 attributes that are not supported, everything else is very good. Chinese needs to quote Chinese fonts. The specific method is briefly explained here:

Code:

$html = '   
测 测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试
'; //echo $html;exit; $options = new Options(); $options->set('enable_remote', TRUE); $dompdf = new Dompdf($options); $dompdf->load_html( $html, 'UTF-8');; // $dompdf->load_html( $html, ‘GBK‘); $dompdf->render(); $dompdf->stream("sample.pdf", array("Attachment"=>0));exit;

Result:

What to do if php dompdf Chinese garbled characters##Need to explain:

10.@font-face

{

font-family:ttt;

src: url(/static/font/simkai.ttf)

}The ttf here is the font, and the location is placed under static/font. In HTML, you can directly use font-family:ttt; to reference it;

2. This is the file dompdf\lib \fonts\dompdf_font_family_cache.php

What to do if php dompdf Chinese garbled charactersIf you need to delete this when migrating the code, or change the name of the family.

Recommended study: "

PHP video tutorial

The above is the detailed content of What to do if php dompdf Chinese garbled characters. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What should I do if php connects to mysql8 and reports an error? Next article:What should I do if php connects to mysql8 and reports an error?

Related articles

See more