我在我的应用程序中使用了Doctrine 1.2.3,我正在尝试使用zend_pdf_table组件基于以下教程http://devzone.zend.com/article/12492-Creating-PDF-Documents-with-Zend-Framework创建PDF报告。
编辑文档已创建,但我只能在报告中显示第一条记录,并且尽管尝试添加自己的样式仍会出现样式错误。
我可能会留下这个,因为我的项目时间不多了,我会从头开始创建自己的PDF。
[error] [client 127.0.0.1] PHP Notice: Trying to get property of non-object in C:\\WebDocs\\xx\\library\\Zend\\Pdf\\Style.php on line 211
我修改后的代码在
下面// report to print todays appointments
public function todaysgroomingappointmentsAction()
{
try{
$t=date('y-m-d');
$q = Doctrine_Query::create()
->select('CONCAT(g.gapmtSTime, g.gapmtETime) AS Time, CONCAT(c.firstname, c.lastname) AS Client, p.name AS Pet, r.groomprocedure AS Procedure, u.name AS Groomer')
->from('PetManager_Model_Groomappointments g')
->leftJoin('g.PetManager_Model_Clients c')
->leftJoin('g.PetManager_Model_Pets p')
->leftJoin('g.PetManager_Model_Users u')
->leftJoin('g.PetManager_Model_Groomservices s')
->leftJoin('s.PetManager_Model_Groomprocedures r')
->where('g.gapmtStatus = 1 AND g.gapmtDate = ?',$t);
$result = $q->fetchArray();
require_once 'Zend/Pdf.php';;
require_once 'My/Pdf.php';
require_once 'My/Pdf/Document.php';
require_once 'My/Pdf/Page.php';
require_once 'My/Pdf/Table.php';
require_once 'My/Pdf/Table/Row.php';
require_once 'My/Pdf/Table/Cell.php';
require_once 'My/Pdf/Table/Column.php';
require_once 'My/Pdf/Table/HeaderRow.php';
// create PDF
$pdf = new My_Pdf_Document('todaysappointments.pdf', 'D:/');
// create page
$page = $pdf->createPage();
// define font resource
$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
// set font
$page->setFont($font, 24);
// create table
$table = new My_Pdf_Table(4);
// iterate over record set
// set up table content
foreach ($result as $record) {
$row = new My_Pdf_Table_Row();
$cols = array();
foreach ($record as $k => $v) {
$col = new My_Pdf_Table_Column();
$col->setText($v);
$cols[] = $col;
}
$row->setColumns($cols);
$row->setFont($font, 14);
$row->setBorder(My_Pdf::TOP, new Zend_Pdf_Style());
$row->setBorder(My_Pdf::BOTTOM, new Zend_Pdf_Style());
$row->setBorder(My_Pdf::LEFT, new Zend_Pdf_Style());
$row->setCellPaddings(array(10,10,10,10));
$table->addRow($row);
}
// add table to page
$page->addTable($table, 0, 0);
// add page to document
$pdf->addPage($page);
// save as file
$pdf->save('todaysappointments.pdf');
echo 'SUCCESS: Document saved!';
} catch (Zend_Pdf_Exception $e) {
die ('PDF error: ' . $e->getMessage());
} catch (Exception $e) {
die ('Application error: ' . $e->getMessage());
}
}
任何人都可以告诉我为什么我会遇到这个错误以及如何解决它。
非常感谢。
答案 0 :(得分:0)
如果你需要保存那么你必须添加一个文件名作为参数到$ pdf-> save(),如果你需要打印出内容你可以使用echo $ pdf-> render(),当然发送pdf的右侧标题。
关于样式,你必须使用Zend_Pdf_Style定义任何样式,而不只是传递空的新Zend_Pdf_Style(),如:
$ style = new Zend_Pdf_Style(); $ style-> setLineColor(new Zend_Pdf_Color_Rgb(0,0,0)); $ style-> setLineWidth(1);