-1

嗨,我正在尝试使用 cakephp 中给出的 TCPDF 手册。

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

但它在我的系统中根本不起作用。我按照那里的确切步骤...

错误:-

 Class 'XTCPDF' not found   

但是我的 Vendor 文件夹中有一个类名 XTCPDF.... 有什么帮助吗?谢谢

4

2 回答 2

3

你尝试改变:

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

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

或者可能遵循本教程: http ://www.pedroventura.com/cakephp/crear-archivos-pdf-con-cakephp/

概括:

文件: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');
        }
    }

?>

文件:app/views/layouts/pdf.ctp

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

控制器中的操作:

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();
}

和文件: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
?>
于 2013-10-27T03:17:00.983 回答
1

http://book.cakephp.org/2.0/en/core-utility-libraries/app.html#loading-vendor-files在这里您会发现,如何在 CakePHP 2.3.6 中加载供应商...

于 2013-06-19T13:36:20.743 回答