-1

Hi i am trying to use the TCPDF manual given in cakephp.

http://bakery.cakephp.org/articles/kalileo/2010/06/08/creating-pdf-files-with-cakephp-and-tcpdf

But its not at all working in my system. I followed the exact steps there...

Error:-

 Class 'XTCPDF' not found   

But there is a class name XTCPDF in my Vendor folder.... Any help plz ?? Thanks

1
  • It's offtopic, but TCPDF is really oldschool. WHy don't you use whhtmltopdf - it generate pretty much WYSIWYG pdf and the only thing is to create a pdf layout for your views. This of course could be used if you can upload the executable of the lib on your hosting and call it. code.google.com/p/wkhtmltopdf Jun 19, 2013 at 14:08

2 Answers 2

3

you try change:

App::import('Vendor','xtcpdf');

to

App::import('Vendor','tcpdf/xtcpdf');

or maybe following this tutorial: http://www.pedroventura.com/cakephp/crear-archivos-pdf-con-cakephp/

summary:

file: app/vendors/tcpdf/xtcpdf.php

<?php

    App::import('Vendor','tcpdf/tcpdf');

    class XTCPDF  extends TCPDF
    {

        var $xheadertext  = 'PDF creado using CakePHP y TCPDF';
        var $xheadercolor = array(0,0,200);
        var $xfootertext  = 'Copyright © %d XXXXXXXXXXX. All rights reserved.';
        var $xfooterfont  = PDF_FONT_NAME_MAIN ;
        var $xfooterfontsize = 8 ;

        function Header()
        {

            list($r, $b, $g) = $this->xheadercolor;
            $this->setY(10);
            $this->SetFillColor($r, $b, $g);
            $this->SetTextColor(0 , 0, 0);
            $this->Cell(0,20, '', 0,1,'C', 1);
            $this->Text(15,26,$this->xheadertext );
        }

        function Footer()
        {
            $year = date('Y');
            $footertext = sprintf($this->xfootertext, $year);
            $this->SetY(-20);
            $this->SetTextColor(0, 0, 0);
            $this->SetFont($this->xfooterfont,'',$this->xfooterfontsize);
            $this->Cell(0,8, $footertext,'T',1,'C');
        }
    }

?>

file: app/views/layouts/pdf.ctp

<?php
header("Content-type: application/pdf");
echo $content_for_layout;
?>

action in controller:

function descargar($id = null)
{
    if (!$id)
    {
        $this->Session->setFlash('no has seleccionado ningun pdf.');
        $this->redirect(array('action'=>'index'));
    }
    Configure::write('debug',0);
    $resultado = $this->MiControlador->findById($id); // info from database
    $this->set("datos_pdf",$resultado);               // info to view (pdf)
    $this->layout = 'pdf';
    $this->render();
}

and file: app/views/mi_aplicacion/descargar.ctp

<?php
App::import('Vendor','tcpdf/xtcpdf'); 
$tcpdf = new XTCPDF();
$textfont = 'freesans';

$tcpdf->SetAuthor("");
$tcpdf->SetAutoPageBreak( false );
$tcpdf->setHeaderFont(array($textfont,'',10));
$tcpdf->xheadercolor = array(255,255,255);
$tcpdf->xheadertext = 'Fecha: '. date('d-m-Y',time());
$tcpdf->xfootertext = 'www.example.cl';

$tcpdf->AddPage();
$tcpdf->SetTextColor(0, 0, 0);
$tcpdf->SetFont($textfont,'B',10);
$tcpdf->Cell(10,20,'Nombre:', 0, 0);

// more info

echo $tcpdf->Output('mi_archivo.pdf', 'D'); //D or I
?>
0
1

http://book.cakephp.org/2.0/en/core-utility-libraries/app.html#loading-vendor-files Here you will find, how do you load vendor in CakePHP 2.3.6...

1
  • 1
    posting links is not answering. links may become broken in the future.
    – stefan
    Jun 19, 2013 at 13:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.