Special fonts in TCPDF pdf

Can someone tell me what I'm doing wrong? I need the Arial font in my pdf created by TCPDF. First I tried to use this: 1) I got Arial from window caltalog fonts and put them in the TCPDF directory. 2) Next, I wrote in the script:

$fontname = $pdf->addTTFfont('../lib/tcpdf/arial.ttf', '', '', 32); 

After that, 3 files appear in tcpdf / fonts (arial.ctg.z, arial.php and arial.z). I thought everything was fine, but if in TCPDF I use this font:

 $pdf->SetFont('arial', '', 16); 

The font in the document is really aryal, but without special curtains (Δ™Δ™Ε‚ΕΌΕ„ΕΊ)

I also tried to prepare the font myself: I downloaded ttf2afm and makefontuni.php script, then on the command line I wrote this:

 ttf2ufm -a arial.ttf php -q makefontuni.php arial.ttf arial.ufm 

this command also gave me 3 files (arial.ctg.z, arial.php and arial.z), but the final situation is the same as before.

I admit that all data records in pdf in UTF-8 and in the TCPDF construct look like this:

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

I don't know what I'm doing wrong .:(

+6
source share
6 answers

If you want to use a special font, use this tool

http://www.xml-convert.com/en/convert-tff-font-to-afm-pfa-fpdf-tcpdf

when you get the generated files, just move them to the / fonts directory and with the same name as theirs, set the font-name attribute.

+13
source

No need to add a font, use the Dejavu Sans font, which has all the UTF-8 characters, and TCPDF already exists.

 $pdf->SetFont('dejavusans', '', 14, '', true); 

http://www.tcpdf.org/examples/example_001.phps

+3
source
 $fontname = TCPDF_FONTS::addTTFfont(FCPATH.'/assets/css/fonts/arial-unicode-ms.ttf'); 

This is what I use to include custom font in TCPDF. You only need a .ttf font file. Add it to the folder of your choice on the server and run this code once. (I run it the first time when exporting). Then you can comment on this line and the font will be there.

To add it to the exporter, you must add it as a font with:

 $pdf->addFont('your-font-name', '', 10, '', false); 

And if you want it to be the default:

 $pdf->setFont('your-font-name', '', 10, '', false); 

If you do not know what the actual font name to use in PDF is:

 echo $fontname; 

This will give you the specific name of the font to be used in the exported file.

After running this command, when TCPDF creates the entire file needed in its font folder, and now it is ready to use.

If you want to re-add the same font (modified), you need to delete the font files in tcpdf / fonts / your-font-name. and run this command again to re-add them.

+1
source

Hm, are you sure your Arial has all the UTF-8 characters? I followed the instructions here http://www.tcpdf.org/fonts.php and it worked. I had problems in that I was able to add a Regular Regular font - as soon as I added Bold or Italic and then changed it one by one, all the characters turned into dots.

So, at the moment I am only using my regular font, and for Bold I am using dejavusans (thanks Miro). My code is:

 $fontname = $pdf->addTTFfont('/lib/tcpdf/fonts/myfont-Regular.ttf','TrueTypeUnicode',''); $pdf->SetFont($fontname, '', 8, '', true); 
0
source

I had the same error as I was able to fix it after the following line:

$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $fontname = $pdf->addTTFfont('tcpdf/fonts/arial.ttf', '', '', 32); $pdf->SetFont('arial', '', 16);

0
source

I think this will help you fix the symbol problem.

 $pdf->SetFont('freeserif', '', 12); 

Above the font family that supports UTF-8 characters.

0
source

Source: https://habr.com/ru/post/905962/


All Articles