如何在TCPDF中显示HTML Ohm特殊字符?

时间:2013-07-16 15:28:35

标签: tcpdf

我正在使用TCPDF从HTML代码生成PDF,我无法正确呈现某些HTML特殊字符。这是我的准系统代码:

require_once('../libraries/tcpdf_6_0_020/tcpdf/tcpdf.php');

// create new PDF document
$pdf = new TCPDF('P', PDF_UNIT, 'LETTER', true, 'UTF-8', false);

// add a page
$pdf->AddPage();

$output = 'this is a special character: Ω';

//echo $output;die();

$pdf->writeHTML($output, true, false, false, false, '');

//Close and output PDF document
$pdf->Output('generated pdf.pdf', 'I');

以上的输出是:

this is a special character: ?

这里有很多关于同一主题的问题,大多数人都说将构造函数更改为以下内容:

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, false, 'ISO-8859-1', false);

我尝试过,但输出变为:

this is a special character: Ω

如何正确渲染HTML特殊字符?

2 个答案:

答案 0 :(得分:6)

试试这个

require_once('tcpdf/tcpdf.php');

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

$pdf->SetFont('dejavusans', '', 10);

$pdf->AddPage();

$html = "this is a special character: Ω";

$pdf->writeHTML($html, true, false, true, false, '');

$pdf->lastPage();

$pdf->Output('test.pdf', 'I');

答案 1 :(得分:0)

对我来说解决方案是

html_entity_decode(utf8_encode('my string'));