developer.jelix.org is not used any more and exists only for history. Post new tickets on the Github account.
developer.jelix.org n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.

Ticket #131: jResponseTcpdf.patch

File jResponseTcpdf.patch, 9.7 KB (added by Julien, 14 years ago)

PDF Response based on TCPDF

  • build/manifests/jelix-lib.mn

     
    6363  jResponseAtom10.class.php
    6464  jResponseCss.class.php
    6565  jResponseLatexToPdf.class.php
     66  jResponseTcpdf.class.php
    6667
    6768cd lib/jelix/core-modules/jelix
    6869  module.xml
     
    222223  jMailer.class.php
    223224  jSmtp.class.php
    224225* jFilter.class.php
     226  jTcpdf.class.php
    225227
    226228cd lib/jelix-modules
    227229  LICENCE
  • lib/jelix/core/response/jResponseTcpdf.class.php

     
     1<?php
     2/**
     3* @package     jelix
     4* @subpackage  core_response
     5* @author      Julien Issler
     6* @contributor
     7* @copyright   2007 Julien Issler
     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*/
     11
     12
     13require_once (JELIX_LIB_UTILS_PATH.'jTcpdf.class.php');
     14
     15/**
     16* PDF Response based on TCPDF (http://tcpdf.sourceforge.net)
     17* @package  jelix
     18* @subpackage core_response
     19*/
     20class jResponseTcpdf  extends jResponse {
     21    /**
     22    * @var string
     23    */
     24    protected $_type = 'tcpdf';
     25
     26    /**
     27     * the tcpdf object you want to send.
     28     * @var object
     29     */
     30    public $tcpdf = null;
     31   
     32    /**
     33     * name of the file under which the file will be send to the user
     34     * @var string
     35     */
     36    public $outputFileName = 'document.pdf';
     37
     38    /**
     39     * Says if the "save as" dialog appear or not to the user.
     40     * @var boolean
     41     */
     42    public $doDownload = false;
     43
     44    /**
     45     * send the PDF to the browser.
     46     * @return boolean    true it it's ok
     47     */
     48    public function output(){
     49
     50        if($this->hasErrors()) return false;
     51
     52        if(!($this->tcpdf instanceof jTcpdf)){
     53            throw new jException('jelix~errors.reptcpdf.not_a_jtcpdf');
     54            return false;
     55        }
     56       
     57        if($this->doDownload)
     58            $this->tcpdf->Output($this->outputFileName,'D');
     59        else
     60            $this->tcpdf->Output($this->outputFileName,'I');
     61       
     62        flush();
     63        return true;
     64    }
     65   
     66    /**
     67     *
     68     */
     69    public function outputErrors(){
     70        global $gJConfig;
     71        $this->clearHttpHeaders();
     72        $this->_httpStatusCode ='500';
     73        $this->_httpStatusMsg ='Internal Server Error';
     74        $this->addHttpHeader('Content-Type','text/plain;charset='.$gJConfig->charset,false);
     75        $this->sendHttpHeaders();
     76        if($this->hasErrors()){
     77            foreach( $GLOBALS['gJCoord']->errorMessages  as $e){
     78               echo '['.$e[0].' '.$e[1].'] '.$e[2]." \t".$e[3]." \t".$e[4]."\n";
     79            }
     80        }else{
     81            echo "[unknow error]\n";
     82        }
     83    }
     84}
     85?>
     86 No newline at end of file
  • lib/jelix/core/defaultconfig.ini.php

     
    4343atom1.0 = jResponseAtom10
    4444css= jResponseCss
    4545ltx2pdf= jResponseLatexToPdf
     46tcpdf = jResponseTcpdf
    4647
    4748[_coreResponses]
    4849html = jResponseHtml
     
    6465atom1.0 = jResponseAtom10
    6566css= jResponseCss
    6667ltx2pdf= jResponseLatexToPdf
     68tcpdf = jResponseTcpdf
    6769
    6870[error_handling]
    6971messageLogFormat = "%date%\t[%code%]\t%msg%\t%file%\t%line%\n"
  • lib/jelix/core-modules/jelix/locales/en_EN/errors.UTF-8.properties

     
    4848repxml.invalid.content=(151) Invalid xml content for xml response
    4949repbin.unknow.file=(152) unknow file for binary response (%s)
    5050repredirect.empty.url=(153) Impossible to do redirection : empty url
     51reptcpdf.not_a_jtcpdf=(154) No jTcpdf object has been provided
    5152
    5253#---- locales
    5354locale.key.selector.invalid= (200)The given locale key "%s" is invalid  ( charset %s, lang %s)
  • lib/jelix/core-modules/jelix/locales/en_EN/errors.ISO-8859-1.properties

     
    4848repxml.invalid.content=(151) Invalid xml content for xml response
    4949repbin.unknow.file=(152) unknow file for binary response (%s)
    5050repredirect.empty.url=(153) Impossible to do redirection : empty url
     51reptcpdf.not_a_jtcpdf=(154) No jTcpdf object has been provided
    5152
    5253#---- locales
    5354locale.key.selector.invalid= (200)The given locale key "%s" is invalid  ( charset %s, lang %s)
  • lib/jelix/core-modules/jelix/locales/en_US/errors.UTF-8.properties

     
    4848repxml.invalid.content=(151) Invalid xml content for xml response
    4949repbin.unknow.file=(152) unknow file for binary response (%s)
    5050repredirect.empty.url=(153) Impossible to do redirection : empty url
     51reptcpdf.not_a_jtcpdf=(154) No jTcpdf object has been provided
    5152
    5253#---- locales
    5354locale.key.selector.invalid= (200)The given locale key "%s" is invalid  ( charset %s, lang %s)
  • lib/jelix/core-modules/jelix/locales/en_US/errors.ISO-8859-1.properties

     
    4848repxml.invalid.content=(151) Invalid xml content for xml response
    4949repbin.unknow.file=(152) unknow file for binary response (%s)
    5050repredirect.empty.url=(153) Impossible to do redirection : empty url
     51reptcpdf.not_a_jtcpdf=(154) No jTcpdf object has been provided
    5152
    5253#---- locales
    5354locale.key.selector.invalid= (200)The given locale key "%s" is invalid  ( charset %s, lang %s)
  • lib/jelix/core-modules/jelix/locales/fr_FR/errors.UTF-8.properties

     
    4848repxml.invalid.content=(151) Contenu xml invalid pour la réponse XML
    4949repbin.unknow.file=(152) Fichier inconnu pour la réponse Binary (%s)
    5050repredirect.empty.url=(153) Impossible de faire la redirection : url non renseignée
     51reptcpdf.not_a_jtcpdf=(154) Aucun objet de type jTcpdf n'a été fourni
    5152
    5253#---- locales
    5354locale.key.selector.invalid= (200)La clef de locale "%s" est invalide  ( charset %s, langue %s)
  • lib/jelix/core-modules/jelix/locales/fr_FR/errors.ISO-8859-1.properties

     
    4848repxml.invalid.content=(151) Contenu xml invalid pour la réponse XML
    4949repbin.unknow.file=(152) Fichier inconnu pour la réponse Binary (%s)
    5050repredirect.empty.url=(153) Impossible de faire la redirection : url non renseignée
     51reptcpdf.not_a_jtcpdf=(154) Aucun objet de type jTcpdf n'a été fourni
    5152
    5253#---- locales
    5354locale.key.selector.invalid= (200)La clef de locale "%s" est invalide  ( charset %s, langue %s)
  • lib/jelix/utils/jTcpdf.class.php

     
     1<?php
     2/**
     3* @package     jelix
     4* @subpackage  utils
     5* @author      Julien Issler
     6* @contributor
     7* @copyright   2007 Julien Issler
     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*/
     11
     12require_once (LIB_PATH.'tcpdf/tcpdf.php');
     13
     14/**
     15 * sub-class of TCPDF, for better Jelix integration (error handling) and easy save to disk feature.
     16 * @package    jelix
     17 * @subpackage utils
     18 */
     19class jTcpdf extends TCPDF {
     20   
     21   
     22    /**
     23     * Throw an exception when an error occurs, instead of die()
     24     * @param string $msg The error's message generated by TCPDF
     25     */
     26    public function Error($msg){
     27        throw new Exception($msg);
     28    }
     29   
     30   
     31    /**
     32     * Method to save the current document to a file on the disk
     33     * @param string $filename The target filename
     34     * @param string $path The target path where to store the file
     35     * @return boolean TRUE if success, else throws a jException
     36     */
     37    public function saveToDisk($filename,$path){
     38       
     39        $data = $this->Output('','S');
     40       
     41        if(!is_dir($path)){
     42            throw new jException('jelix~errors.file.directory.notexists',array($path));
     43        }
     44       
     45        if(file_put_contents(realpath($path).'/'.$filename, $data)){
     46           return true;
     47        }
     48           
     49        if(!is_writable($path)){
     50           throw new jException('jelix~errors.file.directory.notwritable',array($path));
     51        }
     52       
     53        throw new jException('jelix~errors.file.write.error',array($path.'/'.$filename,''));
     54
     55    }
     56   
     57}
     58?>
     59 No newline at end of file