The TCPDF font is not embadding, showing "..." on adobe reader

I added a lot of fonts to TCPDF using this line of code

 TCPDF_FONTS::addTTFfont('fonts/ArchitectsDaughter.ttf', 'TrueTypeUnicode', '', 96); $pdf->AddFont("ArchitectsDaughter"); 

Many other fonts work, but this one does not work. When I open this PDF file in the reader, it shows an error similar to this

cannot extract the built-in font "ArchitectsDaughter". some character may not be displayed or printed correctly.

I am importing a svg file in pdf format. Here is the SVG file that I insert in pdf and you can get the PDF from here and here is the font file .

Here is the complete code that pdf will generate.

 $fileName='export'; $uploadPath = Config::get('constants.paths.uploads.images.base').'/'.$fileName.'.svg'; $pdf = new TCPDF(); TCPDF_FONTS::addTTFfont(dirname(dirname(dirname(dirname(__FILE__)))).'/vendor/font-awesome/fonts/ArchitectsDaughter.ttf', 'TrueTypeUnicode', '', 96); TCPDF_FONTS::addTTFfont(dirname(dirname(dirname(dirname(__FILE__)))).'/vendor/font-awesome/fonts/Archivor.ttf', 'TrueTypeUnicode', '', 96); $pdf->AddFont("Archivor"); $pdf->AddFont("ArchitectsDaughter"); $pdf->SetPrintHeader(false); $pdf->SetPrintFooter(false); $pdf->AddPage(); $pdf->ImageSVG($uploadPath, $x='', $y='', $w='', $h='', $link='', $align='', $palign='', $border=0, $fitonpage=true); $filename = 'export.pdf'; $pdf->output($filename, 'D'); exit; 

Other fonts work fine for me. I don’t know what happens with some fonts. What is the solution for this?

+5
source share
2 answers

According to the documentation, TCPDF_FONTS::addTTFfont() adds the provided font permanently to the font folder and returns its name. Therefore, there is no reason to add it every time, but you must use the added font with the correct name.

 // ... $pdf = new TCPDF(); $fontArchitectsDaughter = TCPDF_FONTS::addTTFfont(realpath(__DIR__ . '/../../../vendor/font-awesome/fonts/ArchitectsDaughter.ttf'), 'TrueTypeUnicode', '', 96); $fontArchivor = TCPDF_FONTS::addTTFfont(realpath(__DIR__ . '/../../../vendor/font-awesome/fonts/Archivor.ttf'), 'TrueTypeUnicode', '', 96); $pdf->AddFont($fontArchivor); $pdf->AddFont($fontArchitectsDaughter); // ... 
+1
source

First, configure the font through TCPDF_FONTS::addTTFfont() or by adding the necessary files to the fonts directory (convert the TTF file through the TCPDF font converter, for example http://fonts.snm-portal.com )

After that activate the font:

$pdf->SetFont('FontAwesome','');

Then write the unicode character using the writeHTML function, starting with & #x and ending with; for example: & # xf0c9; for the f0c9 icon (bars) ( http://fontawesome.io/icon/bars/ ):

$pdf->writeHTML('');

+1
source

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


All Articles