Converting xlsx to PDF with PHPExcel gives ERR_INVALID_RESPONSE

This is my code I use to convert xlsx to pdf. Whenever I run this, I get ERR_INVALID_RESPONSE.
It doesn’t matter whether I use mPDF or dompdf I always get the same result. What could be a problem?

            $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');