您好我正在尝试使用cakephp中提供的TCPDF手册。
http://bakery.cakephp.org/articles/kalileo/2010/06/08/creating-pdf-files-with-cakephp-and-tcpdf
但它根本不在我的系统中工作。我按照那里的确切步骤......
错误: -
Class 'XTCPDF' not found
但我的Vendor文件夹中有一个类名XTCPDF .... 任何帮助PLZ? 谢谢
答案 0 :(得分:3)
你尝试改变:
App::import('Vendor','xtcpdf');
到
App::import('Vendor','tcpdf/xtcpdf');
或者可能遵循本教程: http://www.pedroventura.com/cakephp/crear-archivos-pdf-con-cakephp/
摘要:
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;
?>
控制器中的动作:
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();
}
和 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
?>
答案 1 :(得分:1)
http://book.cakephp.org/2.0/en/core-utility-libraries/app.html#loading-vendor-files在这里你会发现,如何在CakePHP 2.3.6中加载供应商......