#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2011
    Posts
    306
    Rep Power
    6

    PDF Line Breaks??


    So far I have this code:

    Code:
        $_tempY = $this->y;
        $this->y += 10;
        
        $commentsCollection = $invoice->getCommentsCollection(true);
        
        $internalcomments = "Internal Invoice Comments";    
        $page->drawText($internalcomments, 35, $this->y, 'UTF-8'); 
        
                    foreach($commentsCollection as $comm)
                    {
                        $page->drawText($comm->getData('comment'), 235, $this->y, 'UTF-8');
                        $this->y -= 10;
        
                    }
    This code outputs invoice comments into the PDF. However, the comments stretch all the way to the right out of view. I have no idea how to actually put a line break in this. Also, I would like to contain this in a table if possible.

    Any help would be greatly appreciated!
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,381
    Rep Power
    1871
    > $page->drawText($comm->getData('comment'), 235, $this->y, 'UTF-8');
    So what does drawText do?
    Or more specifically, what API are you using, and is there something like drawWrappedText which might offer you the ability to do some formatting.

    If there is no higher level function, you might have to first do
    $t = $comm->getData('comment');

    Then
    - get the length of the text,
    - chop $t into segments of up to 80 characters (however many fit on a line)
    - then draw your list of segments in your loop.

    > foreach($commentsCollection as $comm)
    Are there limits on the length of each comment and the number of comments?
    Would you need to consider spilling a lot of comment onto multiple PDF pages?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper

IMN logo majestic logo threadwatch logo seochat tools logo