[英]How to limit auto break line for draw PDF
我正在使用Zend-pdf繪制從數據庫獲取的數據。 但是當我得到長數據時,它使我繪制重復數據,例如:
就我自己的想法,我想限制數據的長度,如果它的長度比長度長,我希望它能折行<br />
,但是我不知道該怎么做。 這樣每個人都可以解決此問題?我希望很快能收到您的答復! 謝謝。
您可以添加此功能以換行
<?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());
}
?>
您也可以參考此詳細文檔來解決您的問題
希望對您有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.