Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/pdflib.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00047 defined('MOODLE_INTERNAL') || die();
00048 
00050 define('PDF_CUSTOM_FONT_PATH', $CFG->dataroot.'/fonts/');
00051 
00053 define('PDF_DEFAULT_FONT', 'FreeSerif');
00054 
00056 define('K_TCPDF_EXTERNAL_CONFIG', 1);
00057 
00058 // The configuration constants needed by tcpdf follow
00059 
00061 define('K_PATH_MAIN', $CFG->dirroot.'/lib/tcpdf/');
00062 
00064 define('K_PATH_URL', $CFG->wwwroot . '/lib/tcpdf/');
00065 
00067 define('K_PATH_FONTS', K_PATH_MAIN . 'fonts/');
00068 
00070 define('K_PATH_CACHE', $CFG->cachedir . '/');
00071 
00073 define('K_PATH_IMAGES', $CFG->dirroot . '/');
00074 
00076 define('K_BLANK_IMAGE', K_PATH_IMAGES . '/pix/spacer.gif');
00077 
00079 define('K_CELL_HEIGHT_RATIO', 1.25);
00080 
00082 define('K_SMALL_RATIO', 2/3);
00083 
00084 require_once(dirname(__FILE__).'/tcpdf/tcpdf.php');
00085 
00094 class pdf extends TCPDF {
00095 
00101     public function __construct($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8') {
00102 
00103         parent::__construct($orientation, $unit, $format, $unicode, $encoding);
00104 
00105         if (is_dir(PDF_CUSTOM_FONT_PATH)) {
00106             $fontfiles = $this->_getfontfiles(PDF_CUSTOM_FONT_PATH);
00107 
00108             if (count($fontfiles) == 1) {
00109                 $autofontname = substr($fontfiles[0], 0, -4);
00110                 $this->AddFont($autofontname, '', $autofontname.'.php');
00111                 $this->SetFont($autofontname);
00112             } else if (count($fontfiles == 0)) {
00113                 $this->SetFont(PDF_DEFAULT_FONT);
00114             }
00115         } else {
00116             $this->SetFont(PDF_DEFAULT_FONT);
00117         }
00118 
00119         // theses replace the tcpdf's config/lang/ definitions
00120         $this->l['w_page']          = get_string('page');
00121         $this->l['a_meta_language'] = current_language();
00122         $this->l['a_meta_charset']  = 'UTF-8';
00123         $this->l['a_meta_dir']      = get_string('thisdirection', 'langconfig');
00124     }
00125 
00136     public function Output($name='doc.pdf', $dest='I') {
00137         $olddebug = error_reporting(0);
00138         $result  = parent::output($name, $dest);
00139         error_reporting($olddebug);
00140         return $result;
00141     }
00142 
00149     protected function _getfontpath() {
00150         global $CFG;
00151 
00152         if (is_dir(PDF_CUSTOM_FONT_PATH)
00153                     && count($this->_getfontfiles(PDF_CUSTOM_FONT_PATH)) > 0) {
00154             $fontpath = PDF_CUSTOM_FONT_PATH;
00155         } else {
00156             $fontpath = K_PATH_FONTS;
00157         }
00158         return $fontpath;
00159     }
00160 
00164     protected function _getfontfiles($fontdir) {
00165         $dirlist = get_directory_list($fontdir);
00166         $fontfiles = array();
00167 
00168         foreach ($dirlist as $file) {
00169             if (substr($file, -4) == '.php') {
00170                 array_push($fontfiles, $file);
00171             }
00172         }
00173         return $fontfiles;
00174     }
00175 
00176 }
 All Data Structures Namespaces Files Functions Variables Enumerations