Himanshu Bhardiya February 2016

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

I added many fonts in TCPDF using this line of code

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

Many other font is working but, this one is not working. When i opening this pdf into reader, it shows error like this

cannot extract the embedded font 'ArchitectsDaughter'. some character may not display or print correctly.

I am importing svg file in pdf. Here is the SVG file which i inserting in pdf, and you can get PDF from here and here is the font file.

Here is full code how pdf will generates.

$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 working ok for me. Don't know what happening with some fonts. What is the solution for this?

Answers


Gennadiy Litvinyuk February 2016

According to documentation TCPDF_FONTS::addTTFfont() adds the provided font permanently to the fonts folder and returns its name. So there is no reason to add it every time, but it is necessary to use added font with 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);

// ...

Post Status

Asked in February 2016
Viewed 2,910 times
Voted 11
Answered 1 times

Search




Leave an answer