3 ///////////////////////////////////////////////////////////////////////////
5 // NOTICE OF COPYRIGHT //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.org //
10 // Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
12 // This program is free software; you can redistribute it and/or modify //
13 // it under the terms of the GNU General Public License as published by //
14 // the Free Software Foundation; either version 2 of the License, or //
15 // (at your option) any later version. //
17 // This program is distributed in the hope that it will be useful, //
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
20 // GNU General Public License for more details: //
22 // http://www.gnu.org/copyleft/gpl.html //
24 ///////////////////////////////////////////////////////////////////////////
27 * pdflib.php - Moodle PDF library
29 * We currently use the TCPDF library by Nicola Asuni.
31 * The default location for fonts that are included with TCPDF is
32 * lib/tcpdf/fonts/. If $CFG->datadir.'/fonts/' exists, this directory
33 * will be used instead of lib/tcpdf/fonts/. If there is only one font
34 * present in $CFG->datadir.'/fonts/', the font is used as the default
37 * See lib/tcpdf/fonts/README for details on how to convert fonts for use
42 * $doc->print_header = false;
43 * $doc->print_footer = false;
45 * $doc->Write(5, 'Hello World!');
48 * @author Vy-Shane Sin Fat
49 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
56 require_once('tcpdf/tcpdf.php');
61 define('PDF_CUSTOM_FONT_PATH', $CFG->dataroot
.'/fonts/');
62 define('PDF_DEFAULT_FONT', 'FreeSerif');
67 * Wrapper class that extends TCPDF (lib/tcpdf/tcpdf.php).
68 * Moodle customisations are done here.
70 class pdf
extends TCPDF
{
75 function pdf($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8') {
77 parent
::TCPDF($orientation, $unit, $format, $unicode, $encoding);
79 if (is_dir(PDF_CUSTOM_FONT_PATH
)) {
80 $fontfiles = $this->_getfontfiles(PDF_CUSTOM_FONT_PATH
);
82 if (count($fontfiles) == 1) {
83 $autofontname = substr($fontfile[0], 0, -4);
84 $this->AddFont($autofontname, '', $autofontname.'.php');
85 $this->SetFont($autofontname);
86 } else if (count($fontfiles == 0)) {
87 $this->SetFont(PDF_DEFAULT_FONT
);
90 $this->SetFont(PDF_DEFAULT_FONT
);
96 * Fake constructor to keep PHP5 happy.
98 function __construct($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8') {
99 $this->pdf($orientation, $unit, $format, $unicode, $encoding);
105 * Overriding TCPDF::_getfontpath()
107 function _getfontpath() {
110 if (is_dir(PDF_CUSTOM_FONT_PATH
)
111 && count($this->_getfontfiles(PDF_CUSTOM_FONT_PATH
)) > 0) {
112 $fontpath = PDF_CUSTOM_FONT_PATH
;
114 $fontpath = $CFG->dirroot
.'/lib/tcpdf/fonts/';
121 * Get the .php files for the fonts
123 function _getfontfiles($fontdir) {
124 $dirlist = get_directory_list($fontdir);
125 $fontfiles = array();
127 foreach ($dirlist as $file) {
128 if (substr($file, -4) == '.php') {
129 array_push($fontfiles, $file);