koe
koe

Reputation: 746

How to break line when data too long in zend PDF

I am using ZendFramwork 1.7 for my project and now i want to drawtext in pdf but when my data in is too long i need to break line.

this is my data to pass from database that i var_dump enter image description here

And this this my result of problem

enter image description here

I want when name of my site(site_Name) is too long like this or long than it, it's break line automatic. How it can do it ? any sample site/link are welcome.

This is my code

$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
                    $base = realpath(APPLICATION_PATH . '/../public');
                    $image = Zend_Pdf_Image::imageWithPath($base . "/images/logo_login.png");
                    $page->drawImage($image, 60, 547, 80, 563);
                    $page->setLineWidth(0.2)
                            ->drawLine(60, 520, 790, 520);
                    $page->setFont($font, 11)
                            ->drawText("Site", 80, 550)
                            ->drawText("Date " . date("Y-m-d"),705, 550);
                    $i = 0;
                    $pages = 500;
                    $perline = 20;
                    foreach ( $getValueSiteView as $key => $value) {

                        if ($i == 0) {
                            $line = $pages;
                        } else {
                            $line = $pages - ($i * $perline);
                        }
                        $name = $value["site_Name"];
                        $add = $value["site_Adresse1"];
                        $city = $value["site_City"];
                        $Com_Name = $value["Com_Name"];
                        $Com_Add = $value["Com_Address1"];
                        $Com_tel = $value["Com_Telephone"];

                        $page->setFont($font, 9)
                                ->drawText($namee, 60, 530)
                                ->drawText($vil, 120, 530)
                                ->drawText($Adre, 210, 530)
                                ->drawText($comNom, 450, 530)
                                ->drawText($ComTel, 600, 530)
                                ->drawText($conAdd, 700, 530);
                        $page->setFillColor(Zend_Pdf_Color_Html::color('#999999'))
                                ->drawText($name, 60, $line)
                                ->drawText($city, 120, $line)
                                ->drawText($add, 210, $line)->drawText($Com_Name, 450, $line)
                                ->drawText($Com_tel, 600, $line)
                                ->drawText($Com_Add, 700, $line);
                        $i++;
                    }

Thanks in advance.

Upvotes: 2

Views: 2150

Answers (2)

Nouphal.M
Nouphal.M

Reputation: 6344

Say you want a line break every 10 characters, then try,

$name = wordwrap($value["site_Name"],10,'\n',true);

Upvotes: 1

sergio
sergio

Reputation: 5250

Use function substr and strlen():

  $name = strlen($value["site_Name"])>20 ? substr( $value["site_Name"], 0, 19 : $value["site_Name"]

Now, if your $value["site_Name"] have more than 20 characters, for example, it will be cutted

Upvotes: 0

Related Questions