How can I create a button that downloads a pdf file. Problem is that the pdf will get created on the fly (invoice pdf).
Currently I have a admin panel controller and within it there is a printAction
public function printAction() {
$params = $this->getRequest()->getParams();
$order = Mage::getModel("sales/order")->load($order_id);
try {
if(!$order->canInvoice())
{
Mage::throwException(Mage::helper('core')->__('Cannot create an invoice.'));
}
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
$pdf = Mage::getModel('sales/order_pdf_invoice')->getPdf(array($invoice));
echo $pdf->render();
} catch(Exception $e) {
Mage::log($e);
}
}
Currently I have a button like:
<a href="<?php echo Mage::helper('adminhtml')->getUrl('aaa_kitchenboard/index/print'); ?>?orderid=<?php echo $order->getId();?>">Print</a>