使用PHPExcel将xlsx转换为PDF会产生ERR_INVALID_RESPONSE

时间:2017-08-01 09:31:28

标签: php excel pdf phpexcel

这是我用来将xlsx转换为pdf的代码。每当我运行它时,我得到ERR_INVALID_RESPONSE。 无论我使用的是mPDF还是dompdf,我都会得到相同的结果。可能有什么问题?

            $rendererName = PHPExcel_Settings::PDF_RENDERER_DOMPDF;
        $rendererLibrary = 'dompdf.php';
        $rendererLibraryPath = APPPATH."vendor/dompdf/" . $rendererLibrary;
        if (!PHPExcel_Settings::setPdfRenderer(
            $rendererName,
            $rendererLibraryPath
        )) {
            die(
                'Please set the $rendererName and $rendererLibraryPath values' .
                PHP_EOL .
                ' as appropriate for your directory structure'
            );
        }
        $objWriter = PHPExcel_IOFactory::createWriter($spreadsheet, 'Excel2007');
        $objWriter->save($fileName.'.xlsx');
//            readfile($fileName.'.xlsx');
//            header("Content-type:application/xlsx");
//            header('Content-Disposition: 
attachment;filename="'.$fileName.'.xlsx"');
        $objPHPexcel = PHPExcel_IOFactory::load($fileName.'.xlsx');

        header('Content-Type: application/pdf');
        header('Content-Disposition: attachment;filename="test.pdf"');
        header('Cache-Control: max-age=0');

        $objWriter = new PHPExcel_Writer_PDF($objPHPexcel);

        $objWriter->save('test.pdf');

0 个答案:

没有答案