0

I am using Magento 1.9.3

I want to add a static block in invoice pdf. Can I load any static block?

If it is possible then how I can do this?

2
  • you want to where add ? Mar 14, 2019 at 8:21
  • I want to add in invoice PDF
    – SA Soibal
    Mar 14, 2019 at 8:48

1 Answer 1

0

static block in html formate tag available thats why not possible in calling pdf

so you can try below way

Open the file app/code/core/Mage/Sales/Model/Order/Pdf/Invoice.php and add the below function at the end of the file

public function insertConditions($page)
    {
        $page->drawLine(25, $this->y, 570, $this->y); 
        $this->y -= 25;
        $page->drawText(Mage::helper('sales')->__('Your custom text here!'), 35, $this->y, 'UTF-8');
    }

Now, you need to call this insertConditions() function in the getPdf() function like below :

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->insertConditions($page); // the custom text is added here
        $this->_afterGetPdf();
        return $pdf;
    }

PS. I would advice to override the core files instead of changing them directly.

5
  • Hi Rakesh Can you please mention the file location please?
    – SA Soibal
    Mar 14, 2019 at 8:44
  • but where you want ? Mar 14, 2019 at 8:45
  • Should I update here : app\code\core\Mage\Sales\Model\Order\Pdf\Invoice.php
    – SA Soibal
    Mar 14, 2019 at 8:45
  • you can above function end of all function after call this function and add your block id Mar 14, 2019 at 8:47
  • Getting Fatal error: Uncaught Error: Call to a member function createBlock() from app\code\core\Mage\Sales\Model\Order\Pdf\Invoice.php
    – SA Soibal
    Mar 14, 2019 at 8:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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