TCPDF – HTML to PDF conversion, encoding problem for extended chars

In PHP on May 26th, 2011

TCPDF is a-little-great HTML to PDF conversion PHP library. One of main problem, I (and lot others) had encountered displaying extended characters (like European). To resolve this, you need set $unicode parameter false and pass $encoding parameter other character set. Most of given example comes with, $unicode=true and $encoding=’UTF-8′. Below different examples:

Default for UTF-8 unicode:

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

Example of constructor for European charset:

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

Notice above, 4th and 5th params. 4th is $unicode and 5th is encoding params respectively

Example from TCPDF, for extended chars:

  1. PHP: http://www.tcpdf.org/examples/example_008.phps
  2. PDF: http://www.tcpdf.org/examples/example_008.pdf

Further reading:
http://www.tcpdf.org/performances.php (4th point)