[英]Wrapping text in pdf generator PHP
我正在尝试换行,因为当前我的文本不在屏幕上。 下面的代码显示了我如何打印输出。 如何使文本显示在新行中,以便显示在我的PDF文档中。
$page->drawText($this->_patient['referral_comments'], $xPos, $yPos);
如何使文本显示在新行中,以便显示在我的PDF文档中。
您可以使用wordwrap():
(PHP 4> = 4.0.2,PHP 5)wordwrap —将字符串包装为给定数目的字符
例:
// You can change 250 as the width of your pdf
wordwrap($this->_patient['referral_comments'], 250, "\n");
编辑:您应该在代码上做什么:
$page->drawText(wordwrap($this->_patient['referral_comments'], 250, "\n"), $xPos, $yPos);
EDIT2:似乎只有自动换行不起作用,这是另一个建议:
$referral_comments = wordwrap($this->_patient['referral_comments'], 100, "\n");
foreach(explode("\n", $referral_comments ) as $textLine){
if ($textLine!=='') {
$page->drawText(strip_tags(ltrim($textLine)), $xPos, $yPos, 'UTF-8');
$yPos -=14;
}
}
您在这里所做的是每行分别调用$page->drawText
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.