I have a xlsx with only one spreadsheet. I use PHPExcel to convert it to a pdf through the following code:
error_reporting(E_ALL);
date_default_timezone_set('Europe/London');
require_once 'phpExcel/PHPExcel/IOFactory.php';
require_once 'phpExcel/PHPExcel.php';
$inputFileName = 'doc/ModUnico';
$excel2 = PHPExcel_IOFactory::createReader('Excel2007');
$excel2 = $excel2->load($inputFileName.'.xlsx');
$excel2->setActiveSheetIndex(0);
$excel2->getActiveSheet()->setCellValue('H5', '4');
$objWriter = PHPExcel_IOFactory::createWriter($excel2, 'Excel2007');
$objWriter->save($inputFileName.'_.xlsx');
$objPHPexcel = PHPExcel_IOFactory::load($inputFileName.'_.xlsx');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment;filename="test.pdf"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPexcel, 'PDF');
$objWriter->writeAllSheets();
$objWriter->setPreCalculateFormulas(false);
$objWriter->save('php://output');
The problem is that when i try to open the returned file i get the error message "Impossible to read file".
EIDT: Renderer added
$rendererName = PHPExcel_Settings::PDF_RENDERER_MPDF;
$rendererLibrary = 'mpdf.php';
$rendererLibraryPath = dirname(__FILE__).'/MPDF57/' . $rendererLibrary;
if (!PHPExcel_Settings::setPdfRenderer(
$rendererName,
$rendererLibraryPath
)) {
die(
'NOTICE: Please set the $rendererName and $rendererLibraryPath values' .
'<br />' .
'at the top of this script as appropriate for your directory structure'
);
}