PHP + PDF Line Break

后端 未结 2 1370
故里飘歌
故里飘歌 2021-01-21 08:00

I have the below code in my Magento store it adds the customers address to the invoice PDF\'s. Sometimes the lines of the address would be too long for the address labels so I a

2条回答
  •  广开言路
    2021-01-21 08:21

    Magento 1.7

    instead (around line 415 in app/code/local/Mage/Sales/Model/Order/Pdf/Abstract.php if dont have file on this path, copy it from app/code/core/Mage/Sales... location)

    foreach ($payment as $value){
            if (trim($value) != '') {
                //Printing "Payment Method" lines
                $value = preg_replace('/]*>/i', "\n", $value);
                foreach (Mage::helper('core/string')->str_split($value, 50, true, true, "\n") as $_value) {
    
                    $page->drawText(strip_tags(trim($_value)), $paymentLeft, $yPayments, 'UTF-8');
                    $yPayments -= 15;
                }
            }
        }
    

    use this

    foreach ($payment as $value){
            if (trim($value) != '') {
                //Printing "Payment Method" lines
                $value = preg_replace('/]*>/i', "\n", $value);
                foreach (Mage::helper('core/string')->splitWords($value, false,false, "\n") as $_value) {
                    $page->drawText(strip_tags(trim($_value)), $paymentLeft, $yPayments, 'UTF-8');
                    $yPayments -= 15;
                }
            }
        }
    

    also change Mage::helper('core/string')->str_split to Mage::helper('core/string')->splitWords``

提交回复
热议问题