Search code examples
phpkohana-3tcpdf

TCPDF HTML with Special Characters displays empty PDF file


I am using TCPDF Library Version: 5.9.011. I am trying to execute HTML layout as PDF. For which I tried with example provide with the site

$html = '<h1>HTML Example</h1>
<h2>List</h2>
Some special characters: &lt; € &euro; &#8364; &amp; è &egrave; &copy; &gt; \\slash \\\\double-slash \\\\\\triple-slash
';
// output the HTML content
$pdf->writeHTML($html, true, false, true, false, '');

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

Apparently found that generated PDF only default header and footer with middle content blank.

However if I remove special characters like:

$html = '<h1>HTML Example</h1>
<h2>List</h2>
Some special characters:
';

PDF gets its middle content as specified in $html


Solution

  • before line $pdf->writeHTML

    $html = utf8_decode($html);
    

    maybe

    $html = utf8_encode($html);