首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何限制绘制PDF的自动断线

如何限制绘制PDF的自动断线
EN

Stack Overflow用户
提问于 2013-07-30 10:06:29
回答 1查看 1.8K关注 0票数 1

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

对于我自己的想法,我想要限制数据的长度,如果它比长度长,我想要它换行<br />,但我不知道怎么做。那么每个人都可以解决这个问题吗?我期待着看到你的回复!谢谢。

EN

回答 1

Stack Overflow用户

发布于 2013-07-30 11:45:41

您可以添加此函数来换行文本

代码语言:javascript
复制
<?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来解决你的问题

希望这篇文章能对你有所帮助。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17937193

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档