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 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了