2

I know that TCPDF supports special characters and multiple languages. I have tried all the provided fonts. I want to generate the PDF in UTF-8. I know that the included font 'freeserif' for sure includes the character in question. "•"

Here is my current constructor call:

$pdf=new MYPDF('P', 'mm', 'Letter', true, 'UTF-8', false);

Here is an example of the character being generated:

$this->Cell(80,6.35,"• $POST[reportTitle]",0,0,'L',true);

I have also tried replacing the character with its html code:

•

afuzzyllama
  • 6,538
  • 5
  • 47
  • 64
Base Desire
  • 485
  • 1
  • 5
  • 15
  • Is `$POST[reportTitle]` actually `$_POST[reportTitle]`? I don't know whether it is possible to inject stuff into a PDF (JavaScript?) but if you're taking user input, might be worth ensuring it is untainted before you put it in. – halfer May 02 '12 at 15:35
  • Nope, $POST is an array I built myself, which contains the $_POST array a page back. It is not posting to the PDF, I pass it in the $_SESSION. Sorry for the confusion, I didn't think to point that out! – Base Desire May 02 '12 at 16:49
  • Ah cool. Should be `$POST['reportTitle']` to avoid warnings, however. – halfer May 02 '12 at 16:58
  • I agree, however sometimes it confuses PHP when its in parameters. Not sure why. – Base Desire May 02 '12 at 17:23
  • Try wrapping it all in braces (I would anyway, tbh): `"• {$POST['reportTitle']}"` - the issue may be confusion between the outer speech marks and the inner apostrophes - make sure the inner set are apostrophes and not speech marks. – halfer May 02 '12 at 17:45

1 Answers1

2

As seen here :

Set the $unicode parameter on the TCPDF constructor to false and the $encoding parameter to 'ISO-8859-1' or some other character map.

This will help you:

Default for UTF-8 unicode:

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

Example of constructor for European charset:

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, false, 'ISO-8859-1', false);
Community
  • 1
  • 1
adrien
  • 4,399
  • 26
  • 26
  • yeah I already tried that @adrien, but I tried it again just to triple-check it. That makes all characters = The boxes, like this: [] but actually rectangles. Interestingly, if I paste the boxes here, we see that it is coming up as another language: 牥灯 So it is just generating it incorrectly. – Base Desire May 02 '12 at 16:51
  • Are all your PHP code file encoded in UTF-8 ? (check with Notepad++ for example) + is your mysql connection in UTF-8 if you use one ? what about the encoding of your MySQL tables (if any) ? etc.. – adrien May 02 '12 at 16:53
  • 1
    Good idea, tried it though and re-generated it. Refreshed all and posted new data, still the same results though. :( Checking the mysql connection shortly – Base Desire May 02 '12 at 17:21