Mac recognizes generated pdf as excel

Topics: User Forum
Oct 23, 2010 at 7:13 AM


I trying to output a PHPExcel $objPHPExcel as pdf. It works fine on a pc, but on a mac the file is recognized and opens as an excel file. I'm trying to open the file right in the browser, instead of saving it. Does anyone have an idea what could be wrong? Seems that the file contains some information that is recognized as excel file, even though extension is .pdf.

My code is:

    // Create pdf file
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF');
    // Send the headers to allow this document to be sent to the browser rather than saving it to disk
    header("Pragma: no-cache");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Content-Type: application/force-download");
    header("Content-Type: application/octet-stream");
    header("Content-Type: application/download");;
    header("Content-Disposition: attachment;filename=regdata.pdf");
    header("Content-Transfer-Encoding: binary ");

Any clue? Thanks!!!

Oct 25, 2010 at 10:26 AM

Try using header("Content-Type: application/pdf"); instead of the series of Content-Type headers that you have at present.

Oct 31, 2010 at 6:21 AM

Thanks! This works perfectly!