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.

Comments (2) Trackbacks (0)
  1. Thanks for the solution here – this is a first thank you ever I am posting towards a solution as there are not many people with enough knowledge on resolving or troubleshooting issues.

    Your solution worked like a charm for me – I have used TCPDF across many different websites but I was stuck with a site which I couldn’t resolve and your solutions helped me.

    Jay


Leave a comment

(required)

No trackbacks yet.