setfont.htm 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  5. <title>SetFont</title>
  6. <link type="text/css" rel="stylesheet" href="../fpdf.css">
  7. </head>
  8. <body>
  9. <h1>SetFont</h1>
  10. <code>SetFont(<b>string</b> family [, <b>string</b> style [, <b>float</b> size]])</code>
  11. <h2>Description</h2>
  12. Sets the font used to print character strings. It is mandatory to call this method
  13. at least once before printing text or the resulting document would not be valid.
  14. <br>
  15. The font can be either a standard one or a font added via the AddFont() method. Standard fonts
  16. use the Windows encoding cp1252 (Western Europe).
  17. <br>
  18. The method can be called before the first page is created and the font is kept from page
  19. to page.
  20. <br>
  21. If you just wish to change the current font size, it is simpler to call SetFontSize().
  22. <br>
  23. <br>
  24. <strong>Note:</strong> the font definition files must be accessible. They are searched successively in:
  25. <ul>
  26. <li>The directory defined by the <code>FPDF_FONTPATH</code> constant (if this constant is defined)</li>
  27. <li>The <code>font</code> directory located in the same directory as <code>fpdf.php</code> (if it exists)</li>
  28. <li>The directories accessible through <code>include()</code></li>
  29. </ul>
  30. Example using <code>FPDF_FONTPATH</code>:
  31. <div class="doc-source">
  32. <pre><code>define('FPDF_FONTPATH','/home/www/font');
  33. require('fpdf.php');</code></pre>
  34. </div>
  35. If the file corresponding to the requested font is not found, the error "Could not include font
  36. definition file" is raised.
  37. <h2>Parameters</h2>
  38. <dl class="param">
  39. <dt><code>family</code></dt>
  40. <dd>
  41. Family font. It can be either a name defined by AddFont() or one of the standard families (case
  42. insensitive):
  43. <ul>
  44. <li><code>Courier</code> (fixed-width)</li>
  45. <li><code>Helvetica</code> or <code>Arial</code> (synonymous; sans serif)</li>
  46. <li><code>Times</code> (serif)</li>
  47. <li><code>Symbol</code> (symbolic)</li>
  48. <li><code>ZapfDingbats</code> (symbolic)</li>
  49. </ul>
  50. It is also possible to pass an empty string. In that case, the current family is kept.
  51. </dd>
  52. <dt><code>style</code></dt>
  53. <dd>
  54. Font style. Possible values are (case insensitive):
  55. <ul>
  56. <li>empty string: regular</li>
  57. <li><code>B</code>: bold</li>
  58. <li><code>I</code>: italic</li>
  59. <li><code>U</code>: underline</li>
  60. </ul>
  61. or any combination. The default value is regular.
  62. Bold and italic styles do not apply to <code>Symbol</code> and <code>ZapfDingbats</code>.
  63. </dd>
  64. <dt><code>size</code></dt>
  65. <dd>
  66. Font size in points.
  67. <br>
  68. The default value is the current size. If no size has been specified since the beginning of
  69. the document, the value taken is 12.
  70. </dd>
  71. </dl>
  72. <h2>Example</h2>
  73. <div class="doc-source">
  74. <pre><code>// Times regular 12
  75. $pdf-&gt;SetFont('Times');
  76. // Arial bold 14
  77. $pdf-&gt;SetFont('Arial','B',14);
  78. // Removes bold
  79. $pdf-&gt;SetFont('');
  80. // Times bold, italic and underlined 14
  81. $pdf-&gt;SetFont('Times','BIU');</code></pre>
  82. </div>
  83. <h2>See also</h2>
  84. <a href="addfont.htm">AddFont()</a>,
  85. <a href="setfontsize.htm">SetFontSize()</a>,
  86. <a href="cell.htm">Cell()</a>,
  87. <a href="multicell.htm">MultiCell()</a>,
  88. <a href="write.htm">Write()</a>.
  89. <hr style="margin-top:1.5em">
  90. <div style="text-align:center"><a href="index.htm">Index</a></div>
  91. </body>
  92. </html>