Difference between revisions of "Add fonts for embedding"
Revision as of 09:52, 11 August 2016
Additional fonts can be included in Moodle and used by the Certificate module, embedding them in the PDF (when using an "embedded" certificate type).
Add a font from TTF file
Assuming you have a font licensed for converting and embedding...
1. Copy the .ttf file to /lib/tcpdf/fonts
2. Create a "convertfont.php" file in /lib/tcpdf/fonts (and ensure the web server has permissions to run it), containing:
include('../tcpdf.php'); $pdf = new TCPDF_FONTS('P', 'mm', 'A4', true, 'UTF-8', false); $pdf->addTTFfont('./MyFont.ttf', 'TrueTypeUnicode');
3. View the file at http://hostname/lib/tcpdf/fonts/convertfont.php
4. Verify that new files have been created in /lib/tcpdf:
See below for using the font in a certificate.
Add all TCPDF fonts
From /lib/tcpdf/fonts/readme_moodle.txt:This directory contains just selected set of original tcpdf fonts in order to keep the standard Moodle distribution lightweight. You may want to manually download tcpdf package and extract its fonts/ directory into your
$CFG->dataroot/fonts/. In such case, pdflib.php will use this directory. In the future, we plan to have fonts downloadable in a same way as languages are. (TODO MDL-18663).
Using a new font
Once added, there are two ways to use the new font:
- Go to the Certificate module setting page and set it as the new Serif or Sans-serif font. This will apply to all standard certificates.
- Create a custom certificate type in /mod/certificate/type, and replace the $fontserif and $fontsans variables, as needed.
- Replacing font for the whole file:
// $fontsans = get_config('certificate', 'fontsans'); // Comment out old code $fontsans = 'myfont'; // Add new code.
- Replacing font for just the student name:
//certificate_print_text($pdf, $x, $y + 36, 'C', $fontsans, '', 30, fullname($USER)); // Comment out old code certificate_print_text($pdf, $x, $y + 36, 'C', 'myfont', '', 30, fullname($USER)); // Add new code.