TCPDF font not embadding, showing “…” on adobe reader

寵の児 提交于 2019-12-12 10:53:50

问题


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?


回答1:


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);

// ...



回答2:


First set up the font via TCPDF_FONTS::addTTFfont() or by adding the necessary files in the fonts dir (convert the TTF file via a TCPDF font converter like http://fonts.snm-portal.com)

After that, activate the font:

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

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

$pdf->writeHTML('');



来源:https://stackoverflow.com/questions/35268571/tcpdf-font-not-embadding-showing-on-adobe-reader

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!