如何使用zend_pdf库应用自动换行,我使用MyPDFTable lib作为zendPdf lib的扩展。
我使用了以下代码。
<?php
// include auto-loader class
require_once 'Zend/Loader/Autoloader.php';
// register auto-loader
$loader = Zend_Loader_Autoloader::getInstance();
try {
// set up database access parameters
$params = array ('host' => '127.0.0.1',
'username' => 'user',
'password' => 'pass',
'dbname' => 'world');
// configure adapter and query database
$db = Zend_Db::factory('PDO_MYSQL', $params);
$stmt = $db->query('SELECT Name, Code, Region FROM country LIMIT 0, 150');
// create PDF
$pdf = new My_Pdf_Document('example.pdf', '.');
// 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(3);
// iterate over record set
// set up table content
while ($record = $stmt->fetch()) {
$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();
echo 'SUCCESS: Document saved!';
} catch (Zend_Pdf_Exception $e) {
die ('PDF error: ' . $e->getMessage());
} catch (Exception $e) {
die ('Application error: ' . $e->getMessage());
}
?>
您可以在http://devzone.zend.com/1776/creating-pdf-documents-with-zend-framework/主题“转动表格”中找到此代码。
答案 0 :(得分:0)
本教程讲述了您遇到的同样问题。他们也提供了定制解决方案! http://www.ibm.com/developerworks/opensource/tutorials/os-php-zend5/section4.html