HyderA
HyderA

Reputation: 21371

weird characters in my generated PDF

I'm getting 􀀊􀀠􀀉􀀉 characters in my PDF, i've stripped out \r\n \r \n \t, trimmed everything, decoded html entities and stripped tags. Nothing helps. The data is coming from a MySQL database.

Any help would be appreciated.

Upvotes: 3

Views: 3400

Answers (7)

Dwayne Charrington
Dwayne Charrington

Reputation: 6622

Looks like the result of what happens when you copy / paste text from Microsoft word. Does the PDF file contain text from a MS Word document by any chance? That might be your problem. There are some interesting comments for converting and stripping these characters in PHP on the PHP.net website: http://www.php.net/manual/en/function.strtr.php#39383

I am only presuming it is MS Word characters in your PDF file.

Upvotes: 0

Dmytro Zavalkin
Dmytro Zavalkin

Reputation: 5277

Check string encoding (with mb_detect_encoding) before adding to pdf, is it unicode string? Data in MySQL db can be in unicode but your db connection can use some another encoding.

Upvotes: 2

wimvds
wimvds

Reputation: 12850

FPDF doesn't support unicode characters, so that might be the cause of your problem. There's an extension you could try at http://acko.net/node/56, or alternatively you could switch to another PDF generator library (I recommend TCPDF).

Or you could try using iconv to convert the text from UTF-8 to a supported character set (ie. $str = iconv('UTF-8', 'windows-1252', $str);) if you want to stick with FPDF.

Upvotes: 0

dhh
dhh

Reputation: 4337

Have you tried

$string = "testContainingSpecialCharsäöüöüäüß";
$pdf->Cell(0,0,$string);

What characters should have been displayed instead of those 􀀊􀀠􀀉􀀉 things?

Upvotes: 0

Sarfraz
Sarfraz

Reputation: 382696

Try something like this to determine its numeric value and replace it:

$str = 'Hello 􀀊 World';
echo str_replace(chr(ord('􀀊')), '[removed]', $str);

Output:

Hello [removed] World

Upvotes: 0

starmageza
starmageza

Reputation: 11

You might be using a font that is not available.

Upvotes: 0

botmsh
botmsh

Reputation: 1366

Did you try using utf8_decode()? http://php.net/manual/en/function.utf8-decode.php

Upvotes: 0

Related Questions