【问题标题】:Magento: PHP to PDF Invoice - Create new line / Wordwrap ContentMagento:PHP 到 PDF 发票 - 创建新行/自动换行内容
【发布时间】:2012-12-16 23:25:34
【问题描述】:

我正在编辑我的发票文件

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

如果它们的内容很长,我会遇到一个问题,即列会与其他列发生冲突并重叠。例如,在下一列上运行的产品描述。我正在尝试弄清楚如何限制宽度/自动换行/为内容创建新行。

代码是:

// 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
    );
}

我知道“feed”是设置数组从左侧开始的距离(如果所有项目在 CSS 术语中都是“绝对的”,则几乎 = 到左边距)。

但我不确定如何限制它们的宽度和自动换行,这样如果我的制造商很长,它就不会碰到颜色。发票上没有足够的空间来简单地为每个属性提供更多空间。

【问题讨论】:

    标签: php magento pdf pdf-generation magento-1.5


    【解决方案1】:

    答案就在那里:

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

    这里的60是每行显示多少个字符->getName(), 60, true,

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题。当我添加一个新列时,产品描述列消失了。我通过减少 $productDescr 的 str_split 函数中的数字(长度)解决了这个问题。

      【讨论】:

        猜你喜欢
        • 2011-08-20
        • 1970-01-01
        • 1970-01-01
        • 2022-11-12
        • 1970-01-01
        • 2015-05-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多