Reputation: 746
I am using Zend-pdf to draw data that get from database. but when i get a long data it's make me draw duplicate data like:
For my own idea I want limit length of data, if it's long than length I want it break line <br />
,but I can't know how to do it. So everyone can fix this problem?I am looking to see your reply soon ! thanks.
Upvotes: 1
Views: 1954
Reputation: 11853
you can add this function to wrap text
<?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());
}
?>
Also you can refer this detail Document to solve your issue
hope this will sure help you.
Upvotes: 1