1

I have implemented features to export report in pdf.

Following is the code:

            $dompdf_config = new DOMPDF();
            $template = new Template();
            $template->data['products']=$results;
            $html = $template->fetch('report/business_pdf.tpl');
            $dompdf_config->load_html($html);
            $dompdf_config->set_paper('letter', 'portrait');
            $dompdf_config->render();  

            if (file_put_contents('report.pdf', $dompdf_config->output()) !== false) {                    
                $this->redirect('report.pdf');
            }  

but it opens in browser,so how to force it to download?

Updated:

after that I have added code like:

$file = "report.pdf"
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);

and getting download dialog like: enter image description here

there is no open option in dialog,please help me

Er.KT
  • 2,714
  • 1
  • 28
  • 66
  • 2
    I don't know OpenCart, but if you can somehow set MIME types, you can force the user to download it. See http://stackoverflow.com/questions/10615797/utility-of-http-header-content-type-application-force-download-for-mobile – csl Jan 02 '15 at 07:27
  • @csl thanks for your help, I have updated question please check – Er.KT Jan 02 '15 at 08:21
  • 2
    You should use the `stream` method of DOMPDF, see [manual](https://code.google.com/p/dompdf/wiki/FAQ). I doubt this has anything to do with opencart and more with the settings of your browser/computer. – DarkBee Jan 02 '15 at 11:19
  • @DarkBee thanks a lot friend, it works – Er.KT Jan 02 '15 at 12:24

0 Answers0