Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TCPDF UTF-8 symbols not showing up

Tags:

php

pdf

utf-8

tcpdf

Im using latest TCPDF version(5.9). But have some strange problems with encoding. I need Lithuanian language symbols like: ąčęėįšųūž. But get only few of it. Other remain like ????? So what should I do ? I use default times font(it comes with TCPDF download).

Any help would be appreciated.

like image 203
Bounce Avatar asked Mar 17 '11 01:03

Bounce


People also ask

Can UTF-8 represent all Unicode?

Each UTF can represent any Unicode character that you need to represent. UTF-8 is based on 8-bit code units. Each character is encoded as 1 to 4 bytes. The first 128 Unicode code points are encoded as 1 byte in UTF-8.

What characters are UTF-8?

UTF-8 supports any unicode character, which pragmatically means any natural language (Coptic, Sinhala, Phonecian, Cherokee etc), as well as many non-spoken languages (Music notation, mathematical symbols, APL).

Is UTF-8 a character set?

UTF-8 is a character encoding system. It lets you represent characters as ASCII text, while still allowing for international characters, such as Chinese characters.


2 Answers

TCPDF is quite tricky with utf8. Best way to achieve what you want is to embed the font in generated PDF file itself. You can use freeserif font from the TCPDF package, it contains all the utf8 symbols, shows absolutely any character of any language, but adds ~700kb to the output file. That's probably the easiest way to get symbols you need if file size doesn't matter.

You could also make your own font to embed, containing the characters you need. That's probably the best solution, keeping it universal and small in size, but is more complex.

Alternatively, you can relay on core fonts, which are taken from the system, and if not found, replaced by a substitute. This makes output file extremely light, but adds the necessity of font subsetting to obtain exotic chars. Personally I haven't had a success with this, so I still think embedding font is the best solution, which also happens to be more universal..

like image 57
squirrely Avatar answered Sep 24 '22 09:09

squirrely


there is a font included in the CPDF core fonts - dejavusans, it shows all the lithuanian characters. Just add the following:

$pdf->setHeaderFont(Array('dejavusans', '', 10, '', false)); $pdf->setFooterFont(Array('dejavusans', '', 8, '', false)); $pdf->SetFont('dejavusans', '', 10, '', false); 
like image 20
Laurynas Mališauskas Avatar answered Sep 23 '22 09:09

Laurynas Mališauskas