Section: Generating PDF with TCPDF
« Generating an ATOM feed | ^ Responses: generating content | Sending a binary file » |
− Table of content
A jResponseTcpdf
object allows you to generate a PDF and is based on the
TCPDF class (which enhances the famous FPDF).
Download and Install ¶
jResponseTcpdf
is available in a separated module since Jelix 1.5.
It is not included in the main package of Jelix, because of its high weight (fonts).
You have to download the module jtcpdf and you have to install it like any other module.
Use it in a controller ¶
$resp = $this->getResponse('tcpdf');
$resp->outputFileName = 'article.pdf';
$resp->doDownload = true;
// initialise l'objet tcpdf
$resp->initPdf();
$resp->tcpdf->AddPage();
$resp->tcpdf->SetTitle('un titre');
$resp->tcpdf->Text(10,10,'un texte');
...
return $resp;
tcpdf
member of the response is simply a TCPDF
object (or an object
which inherits from TCPDF
). See TCPDF documentation about its use and its
API.
If you want to override some tcpdf methods, you can use your own object. Example:
$resp = $this->getResponse('tcpdf');
$resp->outputFileName = 'article.pdf';
$resp->doDownload = true;
// initialize l'objet tcpdf
$resp->tcpdf = new MyTcPdf();
$resp->tcpdf->AddPage();
$resp->tcpdf->SetTitle('un titre');
$resp->tcpdf->Text(10,10,'un texte');
...
return $resp;
MyTcPdf
of course shall inherit from TCPDF
or jTcpdf
.