James
James

Reputation: 3283

Magento: PHP to PDF Invoice - Create new line / Wordwrap Content

I'm editing my invoices file in

/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php

And I'm running into a problem with columns running into and overlapping other columns if they have long content. eg Product description running over the next column. I'm trying to figure out how to limit the width / word wrap / create a new line for content.

Code is:

// draw Product name
$lines[0] = array(array(
    'text' => Mage::helper('core/string')->str_split($item->getName(), 60, true, true),
    'feed' => 35,
));

// draw SKU
//  $lines[0][] = array(
//    'text'  => Mage::helper('core/string')->str_split($this->getSku($item), 25),
//  'feed'  => 255
//  );

// draw Brand (Added by James)
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $this->getSku($item), array('manufacturer'));

if ($product) {
    $lines[0][] = array(
        'text'  => Mage::helper('core/string')->str_split($product->getAttributeText('manufacturer'), 15),
        'feed'  => 220
    );
}
// draw Colour (Added by James)
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $this->getSku($item), array('pos_short_colour'));

if ($product) {
    $lines[0][] = array(
        'text'  => Mage::helper('core/string')->str_split($product->getAttributeText('pos_short_colour'), 15),
        'feed'  => 320
    );
}

I know that 'feed' is what sets how far in from the left the array starts (pretty much = to a margin-left if all items were 'absolute' in css terms).

But I'm not sure how I can limit their width and word-wrap so that if I have a long manufacturer it won't run into the colour. There isn't enough space on the invoice to just simply give each attribute more room.

Upvotes: 1

Views: 4686

Answers (2)

maya89
maya89

Reputation: 25

I had the same issue. When I added a new column, Product description column disappeared. I solved this by reducing a number (length) in str_split function of $productDescr.

Upvotes: 0

James
James

Reputation: 3283

The answer was right there:

   $lines[0] = array(array(
        'text' => Mage::helper('core/string')->str_split($item->getName(), 60, true, true),
        'feed' => 35,
    ));

The 60 here is how many characters will be displayed per line ->getName(), 60, true,

Upvotes: 1

Related Questions