TCPDF,“不能包含字体定义文件”与OpenType字体 [英] TCPDF, "Could not include font definition file" with OpenType fonts

查看:892
本文介绍了TCPDF,“不能包含字体定义文件”与OpenType字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个网络程序员,对字体没有深入的了解,并且努力让TCPDF包含我们自定义的OpenType字体。我们购买了OpenType字体文件(.oft),它们不受任何类型的DRM保护。



关于这个错误消息的很多问题最终都得到了相同的建议。我已经为TCPDF(755)使用的文件夹设置了正确的文件许可权,并且使用 addTTFfont()来包含.ttf TrueType字体如下所示: / p>

$ pdf-> addTTFfont('/ path-to-font / DejaVuSans.ttf','TrueTypeUnicode','',32);



所以我编写了下面的代码来包含我们的OpenFont类型。 addTTFfont()文档似乎表示支持OpenTypeUnicode和OpenType参数。

$ pdf-> addTTFfont('/ path-to-font / customfont.otf','OpenTypeUnicode','',96);

其中的结果是:
$ b $ TCPDF错误:不能包含字体定义文件:



我们使用的是TCPDF v6.0.020,我一直在阅读 TCPDF字体信息页面到目前为止没有运气。我注意到TCPDF也有 addFont()函数(文档在这里)这似乎更明显的使用,因为它不包括任何字体类型的任何引用。然而,我无法得到这个函数来处理它的小文档。



任何帮助将不胜感激。

addTTFfont()时发生错误吗?解决方案

我之所以问这个问题,是因为我检查了TCPDF代码(只对Counld not include font definition file进行了全局搜索),并且该消息只出现在 addFont()方法。

这两个方法可能有点混乱,但是几个月前我写了一些大量的笔记,我会部分重现,希望它能帮助你不知何故:


  • addTTFfont() - 此方法的主要功能是将字体从TTF(或OTF)转换为TCPDF所需的原始版本。从理论上讲,实现这个功能的方式可以用它作为向文档添加字体的主要方法。它将首先检查tcpdf字体文件夹,如果转换的文件不在那里,它将继续进行转换。这只是一个更多的开销,但仍然不是我向文件添加字体的首选方法,因为您需要知道要转换的字体类型,以便甚至可以成功地运行。国际海事组织,最好使用这种方法来预转换您使用的任何字体,只需使用 addFont()将原始版本添加到文档。
    AddFont() - 这将raw文档,这意味着它可以用来写文本。

  • 你写的下一个文本块的字体。

    $ b $ p 所以我会使用 addTTFfont ()将字体预转换为原始版本,然后使用 addFont() setFont如果 addFont()失败在实际创建PDF的代码中。

    与上面的错误信息,这意味着它无法找到字体定义文件。请记住,如果你用样式集('i','b','bi'等等)调用 addFont(),它所做的就是把它附加到文件名(在扩展名之前)。

    最重要的是,您需要确保您调用 addTTFFont()正在生成原始字体文件并将其保存到您的字体文件夹中。每个样式应该有三个文件,扩展名为 .php .z 。 ctg.z 。所以如果你转换了一个名为 blah.ttf 的字体,你最终会得到 blah.php blah.z blah.ctg.z 。如果转换 blah bold.ttf ,TCPDF将会发现它是一个粗体字体,并在文件名的后面追加'i': blahb.php blahb.z blahb.ctg.z p>

    希望在这里会有一些金块,这将有助于!祝你好运!


    I am a web programmer with no in-depth knowledge of fonts and am struggling to get TCPDF to include our custom OpenType font. We have bought OpenType font files (.oft), which are not protected by any kind of DRM.

    A lot of questions regarding this error message end up getting the same advice. I've set the correct file permissions for the folders used by TCPDF (755) and I have no trouble using the addTTFfont() to including .ttf TrueType fonts like so:

    $pdf->addTTFfont('/path-to-font/DejaVuSans.ttf', 'TrueTypeUnicode', '', 32);

    So I've made up the following code to include our OpenFont type. The addTTFfont() documentation seems to indicate support of OpenTypeUnicode and OpenType parameters.

    $pdf->addTTFfont('/path-to-font/customfont.otf', 'OpenTypeUnicode', '', 96);

    Which results in:

    TCPDF ERROR: Could not include font definition file:

    We're using TCPDF v6.0.020 and I've been reading the TCPDF Fonts information page with no luck so far. I've noticed TCPDF also has the addFont() function (documentation here) which seems more obvious to use as it does not include any reference to any font type. However, I was unable to get this function to work with the little documentation it has.

    Any help would be greatly appreciated.

    解决方案

    Are you sure that you are getting that error when calling addTTFfont()? The reason I ask is because I checked the TCPDF code (just did a global search on "Counld not include font definition file") and that message only appears in the addFont() method.

    These two methods can be a bit confusing, but I wrote myself some copious notes a few months ago, which I will partially reproduce in the hope that it helps you somehow:

    • addTTFfont() - The primary function of this method is to convert a font from TTF (or OTF) to the "raw" version that TCPDF needs. The way this function is implemented you could, in theory, use it as your primary method of adding fonts to a document. It will check the tcpdf font folder first and if the converted files aren't there it will go ahead and do the conversion. It is only a little bit more overhead, but still not my preferred methods of adding fonts to files, as you need to know what style of font you are converting for the process to even work successfully. IMO, it is better to use this method to pre-convert any fonts that you plan on using and simply use addFont() to add the "raw" versions to the document.

    • AddFont() - This adds a "raw" (ie. already converted) font to the document, which means it is then available for writing text with.

    • SetFont() - This sets the font for the next chunk of text that you write.

    So I would use addTTFfont() to pre-convert the font to the "raw" version, then use addFont() and setFont() in the code that actually creates the PDF.

    If addFont() is failing with the error message above, it means it cannot find the font definition file. Keep in mind that if you call addFont() with style set ('i', 'b', 'bi', etc), all it does is append this to the file name (before the extension).

    Most importantly, you need to make sure that you call to addTTFFont() is producing the "raw" font files and saving them into your fonts folder. There should be three files per style, with extensions of .php, .z and .ctg.z. So if you converted a font called blah.ttf you will end up with blah.php, blah.z and blah.ctg.z. If you convert blah bold.ttf, TCPDF will figure out that it is a bold font and append the 'i' to the end of the file names: blahb.php, blahb.z and blahb.ctg.z.

    Hopefully there will be some nugget in here that will help! Good luck!

    这篇关于TCPDF,“不能包含字体定义文件”与OpenType字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆