function getInvoiceAction() { $id = $this->getFiltered('id'); if (!$id) { throw new Am_Exception_InputError("Wrong invoice# passed"); } $invoice = $this->getDi()->invoiceTable->findFirstByPublicId($id); if (!$invoice) { throw new Am_Exception(___("Invoice not found")); } if ($invoice->user_id != $this->user->user_id) { throw new Am_Exception_Security("Foreign invoice requested : [{$id}] for {$this->user->user_id}"); } $pdfInvoice = new Am_Pdf_Invoice($invoice); $pdfInvoice->setDi($this->getDi()); $pdfInvoiceRendered = $pdfInvoice->render(); $this->noCache(); header("Content-type: application/pdf"); header("Content-Length: " . strlen($pdfInvoiceRendered)); header("Content-Disposition: attachment; filename={$pdfInvoice->getFileName()}"); echo $pdfInvoiceRendered; }