2

I want to add text to the pdf invoice in the marked arena (see photo).

I'm using Magento version 1.9.2.1

How can I do this?

pdf invoice

0

You can add specific text after total price follow the code

First override that block add this code in your config file between <global/>:

<models>
        <sales>
            <rewrite>
                <order_pdf_invoice>Namespace_Module_Model_Order_Pdf_Invoice</order_pdf_invoice>
            </rewrite>
        </sales>
    </models>

Create file in app/code/local/Namespace/Module/Model/Order/Pdf/Invoice.php and add the below function at the end of the file:

<?php 
class Mage_Sales_Model_Order_Pdf_Invoice extends Mage_Sales_Model_Order_Pdf_Abstract 
{
   public function insertText($page)
   {
     $page->drawLine(25, $this->y, 570, $this->y); 
     $this->y -= 25;
     $page->drawText(Mage::helper('sales')->__('Add here Your custom text'), 35, $this->y, 'UTF-8');
 }

Now, you need to call this insertText() function in the getPdf() function and add this getPdf() function after insertText() function like here:

public function getPdf($invoices = array())
{
    $this->_beforeGetPdf();
    $this->_initRenderer('invoice');

    $pdf = new Zend_Pdf();
    $this->_setPdf($pdf);
    $style = new Zend_Pdf_Style();
    $this->_setFontBold($style, 10);

    foreach ($invoices as $invoice) {
        if ($invoice->getStoreId()) {
            Mage::app()->getLocale()->emulate($invoice->getStoreId());
            Mage::app()->setCurrentStore($invoice->getStoreId());
        }
        $page  = $this->newPage();
        $order = $invoice->getOrder();
        /* Add image */
        $this->insertLogo($page, $invoice->getStore());
        /* Add address */
        $this->insertAddress($page, $invoice->getStore());
        /* Add head */
        $this->insertOrder(
            $page,
            $order,
            Mage::getStoreConfigFlag(self::XML_PATH_SALES_PDF_INVOICE_PUT_ORDER_ID, $order->getStoreId())
        );
        /* Add document text and number */
        $this->insertDocumentNumber(
            $page,
            Mage::helper('sales')->__('Invoice # ') . $invoice->getIncrementId()
        );
        /* Add table */
        $this->_drawHeader($page);
        /* Add body */
        foreach ($invoice->getAllItems() as $item){
            if ($item->getOrderItem()->getParentItem()) {
                continue;
            }
            /* Draw item */
            $this->_drawItem($item, $page, $order);
            $page = end($pdf->pages);
        }
        /* Add totals */
        $this->insertTotals($page, $invoice);
        if ($invoice->getStoreId()) {
            Mage::app()->getLocale()->revert();
        }
    }
    $this->insertText($page);  // your custom text is added here
    $this->_afterGetPdf();
    return $pdf;
}

$this->insertText($page); that call your custom text function so you need to add before $this->_afterGetPdf(); this function.

  • Thank for your comment. In which config file should I add the code and what do you mean with Namespace? – NielN98 Nov 20 '16 at 15:58
  • Actually you have to create your own module to override model class.So please follow this link for understand about Namespace and also how to create module : code.tutsplus.com/tutorials/… – Sneha Panchal Nov 21 '16 at 8:54
0

I was able to add text to the invoice pdf by creating a local copy of the core directory(files/folders) app/code/core/Mage/Sales/Model/Order/Pdf/Invoice.php as app/code/local/Mage/Sales/Model/Order/Pdf/Invoice.php and added the insertText() function as stated above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.