如何解决需要在Zend Framework中创建PDF的帮助
|| 我在应用程序中使用了Doctrine 1.2.3,并且尝试根据以下教程http://devzone.zend.com/article/12492-Creating-PDF-Documents-with-Zend-创建PDF报告框架使用zend_pdf_table组件。 编辑创建了文档,但是尽管尝试添加我自己的样式,但我只能获得第一个记录出现在报表上,并且仍然出现样式错误。 我可能会在项目用完的时候留下这个,我会从头开始创建自己的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));
$table->addRow($row);
}
// add table to page
$page->addTable($table,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());
}
}
谁能告诉我为什么会得到这个错误以及如何解决。
非常感谢。
解决方法
如果需要保存,则必须将文件名添加为$ 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);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。