I'm trying to find a way to print an order's invoice programatically. For that I tried to get the url that Magento uses in backend to print an invoice but it didn't help as it uses a key that I couldn't find a way to retrieve it. I'm now trying another solution, is to code a controller function that renders the invoice pdf :

public function printOrderAction() {

        $order_id=json_decode( $this->getRequest()->getParam('order_id'));

        $orderObject = Mage::getModel('sales/order')->load($order_id);

        $invoiceCollection = $orderObject->getInvoiceCollection();
        foreach($invoiceCollection as $inv) {
            $invoice = $inv;

        $pdf = Mage::getModel('sales/order_pdf_invoice')->getPdf(array($invoice));
        $this->_prepareDownloadResponse('invoice'.Mage::getSingleton('core/date')->date('Y-m-d_H-i-s').'.pdf', $pdf->render(), 'application/pdf');

This function, when triggering it, gives that error Not valid template file:frontend\base\default\template\payment/info/pdf/checkmo.phtml

Is there any solution for that error? Or perhaps that there is an other simpler way to get the order's invoice ?

  • you are tring to generate order invoice programetically? Commented Dec 30, 2016 at 13:20
  • @DhirenVasoya exactly . Any idea ? Commented Dec 30, 2016 at 14:29
  • I added answer, please check and if it work them accept, so other get help in community. Commented Dec 31, 2016 at 3:11

1 Answer 1


Here are code to generate invoice from the order.

    $order = Mage::getModel("sales/order")->load($order_id);

      Mage::throwException(Mage::helper('core')->__('Cannot create an invoice.'));

    $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();

    if (!$invoice->getTotalQty()) 
       Mage::throwException(Mage::helper('core')->__('Cannot create an invoice without products.'));

    $transactionSave = Mage::getModel('core/resource_transaction')

catch (Mage_Core_Exception $e) 

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.