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 "Could 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 notes a few months ago, which I will partially reproduce below 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 method 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.
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 your 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 'b' 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!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…