tecnickcom / TCPDF

Official clone of PHP library to generate PDF documents and barcodes
https://tcpdf.org
Other
4.21k stars 1.52k forks source link

TCPDF Showing Question Marks using Math symbols #649

Open muhammadazeemlums opened 1 year ago

muhammadazeemlums commented 1 year ago

Hi, I am facing issue in math symbols using tcpdf it showing ??? marks on pdf. is there any solution to handle it?

atm-florianm commented 3 months ago

@muhammadazeemlums We had a similar problem, which we solved by using a TTF font that provides the glyphs for those characters. Be careful however, because you need a font with all the glyphs you want to be able to use, so it should not just cover misc symbols, it should also have your usual script (including possible diacritics etc.).

I didn't find such a font yet, but I admit I didn't spend a lot of time searching.

Once you have found the font, there are still a few possible hurdles:

  1. you don't just need one ttf file, but one for regular, one for bold, one for italic and one for bold italic (if you intend to use these variants).
  2. for each of the ttf files, you need to use tools/tcpdf_addfont.php -i path/to/your/ttf/mycustomfont.ttf -o path/to/your/tcpdf/fonts/directory, which generates sort of cache files that TCPDF requires to be able to use the font. You don't have to do that every time you generate a PDF, only once for each font.
  3. once your files are there, in the script that generates your PDF, you can use TCPDF's method AddFont('mycustomfont', '', 'path/to/your/tcpdf/fonts/directory/mycustomfont.ttf', 'default') (as many times as you have variants: regular, bold, italic, bold italic…).

It would be really cool if TCPDF had a kind of fallback mechanism (i.e. when a glyph is not found using the current font, TCPDF looks up the character in another font that is more likely to have the corresponding glyph).