I'm trying to create a pdf with TCPDF in magento, i need to import a image or a pdf and modify it. my code in firefox works good but doesn't work in chrome or in internet.
i put a little of my code:
my controller:
public function printAction()
{
if (($cardCode = $this->getRequest()->getParam('code'))) {
$this->loadLayout('print');
$this->getResponse()->clearHeaders()
->setHeader('Content-Type', 'application/pdf');
$this->renderLayout();
} else {
$this->_redirect('/');
}
}
My phtml:
require_once('tcpdf/tcpdf.php');
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetFont('helvetica', '', 15);
$pdf->AddPage();
$pdf->setJPEGQuality(100);
$fileName = Mage::getConfig()->getOptions()->getMediaDir()."/pdf/Gutschein-v2.jpg";
$pdf->Image($fileName, 0, 0, 210, 266, 'JPG', '', '', true, 150, '', false, false, 1, false, false, false);
if ($giftCard->getMailTo()) {
$name = $this->helper('core')->escapeHtml($giftCard->getMailTo(), null);
}
if ($giftCard->getMailFrom()) {
$from = $this->helper('core')->escapeHtml($giftCard->getMailFrom(), null);
}
$code=$giftCard->getCardCode();
$currency= Mage::helper('core')->currency($giftCard->getCardAmount(), true, false);
$pdf->MultiCell(80, 5, $name."
", 1, 'J', 1, 1, 60, 102, true);
$pdf->MultiCell(80, 5, $from."
", 1, 'J', 1, 1, 60, 123, true);
$pdf->MultiCell(80, 5, $currency."
", 1, 'J', 1, 1, 60, 145, true);
$pdf->MultiCell(80, 5, $code."
", 1, 'J', 1, 1, 60, 166, true);
$pdf->lastPage();
ob_start();
$pdf->Output('example_009.pdf', 'I');
ob_end_flush();
I can see the pdf perfectly in firefox but not download and open it from my computer. Error: pdf ist damaged.
In internet and google chrome i can't see the pdf.
I don't know waht i'm doing wrong. thank you.