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.

Opened 11 years ago

Closed 11 years ago

#1042 closed new feature (wontfix)

core : responseTcpdf adding its own Tcpdf Class

Reported by: isepman Owned by: isepman
Priority: normal Milestone:
Component: jelix:core response Version: 1.1.4
Severity: normal Keywords: pdf
Cc: dhuguet@… Blocked By:
Blocking: Documentation needed: no
Hosting Provider: Php version:

Description

Tcpdf class has two method that can be overwritten (Header and Footer). But jResponseTcpdf uses its own class (jTcpdf). I wanted to use my own header and footer method (and also use callback, add background to all my pdfs generated by Jelix). Thus, I wrote this patch which allows me to write my own class. We can use it like this :

$rep = $this->getResponse('tcpdf');
$rep->setTcpdfClass('exportsPdf~maClasse');
$rep->initPdf();

And in app/modules/exportsPdf/classes/maClasse.class.php :

class maClasse extends jTcpdf { //The class must extends jTcpdf to keep jelix easy-save features

    public function __construct($orientation, $unit, $format, $encoding){
    parent::__construct($orientation, $unit, $format, $encoding)
    }

    public function Header(){
    //Add your own header to the pdfResponse
    }

    public function Footer(){
    //Add Your own footer
    }
}

I know I could have done a 'pdf' Response in defaultconfig.ini.php and write my own Response there but I didn't need to add anything to the other jelix function (outputErrors ...etc,), and we are not modifying the response here, we are touching to Tcpdf class.
Sorry for my english...
Here is the patch

Attachments (1)

responseTcpdf.diff (2.4 KB) - added by isepman 11 years ago.

Download all attachments as: .zip

Change History (5)

Changed 11 years ago by isepman

comment:1 Changed 11 years ago by isepman

  • Cc dhuguet@… added

comment:2 Changed 11 years ago by laurentj

  • review review? deleted

thanks for your patch, but I think it is useless. don't call initPdf, just set the tcpdf property with the object you instancy yourself, as indicated in the manual http://jelix.org/articles/fr/manuel-1.1/responsetcpdf#utilisation-dans-une-action . Does it fit your need ?

comment:3 Changed 11 years ago by isepman

That exactly fits my needs, I realize that I "me suis pris la tête", Thanks for the advise and sorry for disturbing...

However, there is a little mistacke in the documentation. "L'objet dans la propriété tcpdf est tout simplement un objet TCPDF."

should be

"L'objet dans la propriété tcpdf est tout simplement un objet jTCPDF."

and

"MyTcPdf? étant l'objet qui hérite de TCPDF. "

should be

"MyTcPdf? étant l'objet qui hérite de jTCPDF. "

because in the jResponseTcpdf file, line 57 (function output):

if(!($this->tcpdf instanceof jTcpdf))
            throw new jException('jelix~errors.reptcpdf.not_a_jtcpdf');

comment:4 Changed 11 years ago by laurentj

  • Resolution set to wontfix
  • Status changed from new to closed

This is not really a mistack, since jTcpdf inherits from TCPDF ;-) But you're right, the manual should be more clear. I fixed it.

Note: See TracTickets for help on using tickets.