I'm using Doctrine 1.2.3 in my application and I am trying to create a PDF report based on the following tutorial http://devzone.zend.com/article/12492-Creating-PDF-Documents-with-Zend-Framework using the zend_pdf_table component.
EDIT The document is created but I can only get the first record to appear on the report and still getting the style error despite trying to add my own style.
I may leave this as I am running out of time on the project, I'll look at creating my own PDF from scratch.
[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
My revised code is below
// 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开发者_如何学C.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());
}
}
Can anyone tell me why I'getting this error and how I can fix it.
Many thanks.
If you need to save then you must add a filename as argument to $pdf->save(), if you need just print out the content you can use echo $pdf->render(), of course with sending right headers for pdf.
About styles, you must define any style using Zend_Pdf_Style, not just pass empty new Zend_Pdf_Style(), something like:
$style = new Zend_Pdf_Style(); $style->setLineColor( new Zend_Pdf_Color_Rgb( 0, 0, 0 ) ); $style->setLineWidth( 1 );
精彩评论