anebg 2 geek life, brainstorm, computing!

7Sep/112

TCPDF returns an empty page with just the headers when writing HTML

First, make sure your HTML is valid.
Second, make sure your encoding is true to what your TCPDF construction, for example :

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

Is creating a UTF8 pdf document. So, before you pass in your $html variable, utf8 encode it.

$pdf->writeHTML(utf8_encode($html), true, 0, true, 0);

I use it in a site where lots of users input pasted text from MS Word, and it seems that it comes with a bunch of weird characters that break TCPDF, utf8 encoding fixed a bunch of seemingly 'random' blank generated PDFs.