dprfe04886 2013-07-26 20:23
浏览 67
已采纳

tcpdf自定义字体未被使用

I'm using the TCPDF library to generate a PDF file with PHP. I want to use a custom font so I used the addTTFfont method to add my custom TrueType font files. The font I am trying to add is "Aller" from fontsquirrel.com

$aller = $pdf->addTTFfont($_SERVER['DOCUMENT_ROOT'].'/includes/fonts/Aller/Aller_Rg.ttf', 'TrueTypeUnicode', '', 32);

This created the files aller_rg.php, aller_rg.ctg.z, and aller_rg.z in my TCPDF fonts folder. The K_PATH_FONTS constant points to this directory. The addTTFfont method returns the string name of the font. It would return false if there was an error so the problem is probably not here..

I then tried to use the font

$pdf->SetFont($aller, '', 16); // or $pdf->SetFont('aller_rg', '', 16);
$pdf->Write(0,"abcdefg",'',0,'L',true,0,false,true,0);

The pdf is generated without any errors. When viewsed in the browser preview the font is clearly not aller but just a generic sans-serif.. When I open the pdf in Mac's Preview application the sections that are using the aller font are blank (no text displays).

Anyone know what I'm doing wrong?

  • 写回答

2条回答 默认 最新

  • dongyi1215 2013-07-26 21:56
    关注

    Got it to work by using this tool

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

    it generates a .php, .z, and .afm file that you put in the TCPDF fonts directory. I'm still not sure what the problem was. the addTTFfont() method doesn't create the .afm file so maybe that's it?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题