我有一个多语言的工具。它在英语、法语、德语和西班牙语等多种语言中发挥了很大的作用。我试图增加对简体中文的支持。问题是,我需要将字体系列转换为支持汉字的字体。
在我的代码中,我把一些逻辑转换为支持中文的字体,但它似乎不起作用。
$lang = 'zh';
...
$pdf->SetFont(($lang == 'zh' ? 'cid0cs' : 'Helvetica'), 'I', 8);
我遗漏了什么?
发布于 2020-05-14 15:20:42
请使用msungstdlight作为简体/繁体中文。
示例代码:$pdf->SetFont('msungstdlight','',9);
希望会帮助你。
发布于 2020-04-25 09:46:31
它适用于我(除非你认为我的示例文本不是简体中文):
<?php
// Include the main TCPDF library
require_once('TCPDF-master/tcpdf.php');
// Create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// Set font
$lang = 'zh';
$pdf->SetFont(($lang == 'zh' ? 'cid0cs' : 'Helvetica'), 'I', 8);
// Add a page
$pdf->AddPage();
// Set some content to print
$html = <<<EOD
<p>简化字</p>
EOD;
// Print text using writeHTMLCell()
$pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
// Close and output PDF document
$pdf->Output('test_TCPDF.pdf', 'I');
https://stackoverflow.com/questions/61277752
复制相似问题