Source for file jTcpdf.class.php

Documentation is available at jTcpdf.class.php

  1. <?php
  2. /**
  3. @package     jelix
  4. @subpackage  utils
  5. @author      Julien Issler
  6. @contributor Laurent Jouanneau
  7. @copyright   2007-2008 Julien Issler, 2007 Laurent Jouanneau
  8. @link        http://www.jelix.org
  9. @licence     GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
  10. @since 1.0
  11. */
  12.  
  13. /**
  14.  *
  15.  */
  16. require_once (LIB_PATH.'tcpdf/tcpdf.php');
  17.  
  18. /**
  19.  * sub-class of TCPDF, for better Jelix integration (error handling) and easy save to disk feature.
  20.  * @package    jelix
  21.  * @subpackage utils
  22.  * @since 1.0
  23.  */
  24. class jTcpdf extends TCPDF {
  25.  
  26.     public function __construct($orientation='P'$unit='mm'$format='A4'$encoding=null{
  27.  
  28.         if($encoding === null)
  29.             $encoding $GLOBALS['gJConfig']->charset;
  30.  
  31.         parent::__construct($orientation$unit$format($encoding == 'UTF-8' || $encoding == 'UTF-16')$encoding);
  32.         
  33.         $this->setHeaderFont(array('vera','',10));
  34.         $this->setFooterFont(array('vera','',10));
  35.     }
  36.  
  37.  
  38.     /**
  39.      * Throw an exception when an error occurs, instead of die()
  40.      * @param string $msg The error's message generated by TCPDF
  41.      */
  42.     public function Error($msg){
  43.         throw new Exception($msg);
  44.     }
  45.  
  46.  
  47.     /**
  48.      * Method to save the current document to a file on the disk
  49.      * @param string $filename The target filename
  50.      * @param string $path The target path where to store the file
  51.      * @return boolean TRUE if success, else throws a jException
  52.      */
  53.     public function saveToDisk($filename,$path){
  54.  
  55.         $data $this->Output('','S');
  56.  
  57.         if(!is_dir($path)){
  58.             throw new jException('jelix~errors.file.directory.notexists',array($path));
  59.         }
  60.  
  61.         if(file_put_contents(realpath($path).'/'.$filename$data)){
  62.            return true
  63.         }
  64.  
  65.         if(!is_writable($path)){
  66.            throw new jException('jelix~errors.file.directory.notwritable',array($path));
  67.         }
  68.  
  69.         throw new jException('jelix~errors.file.write.error',array($path.'/'.$filename,''));
  70.  
  71.     }
  72.  
  73. }
  74. ?>

Documentation generated on Wed, 07 Sep 2011 13:48:06 +0200 by phpDocumentor 1.4.3