我正在使用Zend-pdf来绘制从数据库获得的数据。但是当我得到一个很长的数据时,它会让我绘制重复的数据,比如:

对于我自己的想法,我想要限制数据的长度,如果它比长度长,我想要它换行<br />,但我不知道怎么做。那么每个人都可以解决这个问题吗?我期待着看到你的回复!谢谢。
发布于 2013-07-30 11:45:41
您可以添加此函数来换行文本
<?php
// include auto-loader class
require_once 'Zend/Loader/Autoloader.php';
// register auto-loader
$loader = Zend_Loader_Autoloader::getInstance();
// define long string
$str = "Mary had a little lamb. It's fleece was white as snow. And everywhere that Mary went, the lamb was sure to go";
try {
// create PDF
$pdf = new Zend_Pdf();
// create A4 page
$page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
// define font resource
$font = Zend_Pdf_Font::fontWithPath('/tmp/comic.ttf');
// set font
$page->setFont($font, 14);
// wrap lines of text
// start at (10,600) and use a block of dimensions 500x500
$page->drawTextBlock($str, 10, 600, 500, 500, Zend_Pdf_Page::ALIGN_LEFT);
// wrap lines of text
// start at (10,500) and use a block of dimensions 200x300
$page->setFont($font, 20);
$page->drawTextBlock($str, 10, 500, 200, 300, Zend_Pdf_Page::ALIGN_RIGHT);
// add page to document
$pdf->pages[] = $page;
// save as file
$pdf->save('example.pdf');
echo 'SUCCESS: Document saved!';
} catch (Zend_Pdf_Exception $e) {
die ('PDF error: ' . $e->getMessage());
} catch (Exception $e) {
die ('Application error: ' . $e->getMessage());
}
?>你也可以参考这个detail Document来解决你的问题
希望这篇文章能对你有所帮助。
https://stackoverflow.com/questions/17937193
复制相似问题