1

I'm using a pdf generator class(TCPDF) to generate a pdf file from some html. The problem is that that html text has some utf8 and unicode characters. This class has support for those characters.

I've made the settings and all works just fine on localhost. But when I upload the files to my web host, I get a white page. I use exacty the same code.

If I delete the unicode and utf-8 characters it works. I've copied the script but on the server it is not working. It is there a php setting for handling those characters? Something in php.ini maybe? Thank you

6
  • 2
    Add ini_set('display_errors', 1); error_reporting(~0); to the top of your script and look for error messages getting displayed if you you can't find the error log. Commented Oct 4, 2011 at 18:47
  • I'm using this on a joomla platform. I've got some errors, bot nothing related to my files wic I'm working with. Also, nothing with mb_ Commented Oct 4, 2011 at 18:55
  • Could it be, that you used '\' instead of '/' as path delimiter to include your library? This would work on Windows, but on the server you should use require_once('lib/tcpdf/tcpdf.php') instead. Commented Oct 4, 2011 at 19:15
  • but I am not getting any error from that side. It works when I delete the unicode characters . . . ohh :( Commented Oct 4, 2011 at 19:18
  • How do you get this unicode characters, did you save the php file as UTF8 or do they come from a database query? Commented Oct 4, 2011 at 19:41

1 Answer 1

1

As well as making sure that PHP has the mbstring extension installed, make sure you're setting PHP's encoding in the script with mb_internal_encoding('UTF-8'); or in php.ini.

You also need to make sure that the font being specified in TCPDF has support for UTF-8 characters. I've had big problems with this over the years and eventually just decided to use the Freesans and Freeserif fonts that are bundled with TCPDF.

Also when instantiating the TCPDF class make sure you have set the 4th and 5th parameters of the class constructor. If omitted they should default to TRUE, UTF-8 but I always specify to make sure.

$pdf=new PDF('P', 'mm', 'A4', TRUE, 'UTF-8');
$pdf->SetPageOrientation('P', FALSE, $margin_v);
$pdf->SetMargins($margin_h, $margin_v, $margin_h, TRUE);

// USE BUNDLED freesans FONT FOR DECENT UTF-8 SUPPORT
$pdf->setFontSubsetting(TRUE);
$pdf->SetFont('freesans', '', 11);

Check the docs for the TCPDF constructor

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.