Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Are you sure that you are getting that error when calling <code>addTTFfont()</code>? 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 <code>addFont()</code> method.</p> <p>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:</p> <ul> <li><p><code>addTTFfont()</code> - 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 <code>addFont()</code> to add the "raw" versions to the document.</p></li> <li><p><code>AddFont()</code> - This adds a "raw" (ie. already converted) font to the document, which means it is then available for writing text.</p></li> <li><p><code>SetFont()</code> - This sets the font for the next chunk of text that you write.</p></li> </ul> <p>So I would use <code>addTTFfont()</code> to pre-convert the font to the "raw" version, then use <code>addFont()</code> and <code>setFont()</code> in the code that actually creates the PDF.</p> <p>If <code>addFont()</code> is failing with the error message above, it means it cannot find the font definition file. Keep in mind that if you call <code>addFont()</code> with style set ('i', 'b', 'bi', etc), all it does is append this to the file name (before the extension).</p> <p>Most importantly, you need to make sure that your call to <code>addTTFFont()</code> is producing the "raw" font files and saving them into your fonts folder. There should be three files per style, with extensions of <code>.php</code>, <code>.z</code> and <code>.ctg.z</code>. So if you converted a font called <code>blah.ttf</code> you will end up with <code>blah.php</code>, <code>blah.z</code> and <code>blah.ctg.z</code>. If you convert <code>blah bold.ttf</code>, TCPDF will figure out that it is a bold font and append the 'b' to the end of the file names: <code>blahb.php</code>, <code>blahb.z</code> and <code>blahb.ctg.z</code>.</p> <p>Hopefully there will be some nugget in here that will help! Good luck!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload