It is required after uploading the XLSX or XLS document to the server, immediately convert it to PDF and give it to the client.

Used PHPExcel, PhpSpreadsheet, FPDF, but, unfortunately, did not work.

Now I have a code (PHPExcel) that saves the source file, after saving it converts to PDF and gives it to the client, but the resulting file cannot be opened and its size is suspiciously small.

I know that such topics were even found something on third-party resources, but as a result I came across numerous errors that could not be defeated, or it worked no better than they are now.

$newname = "../../excel/".$_POST['par1']."/".$_POST['par2'].".xlsx"; if((move_uploaded_file($_FILES['uploadfile']['tmp_name'], $newname))) { $pdf_path = "../../pdf/{$_POST['par1']}/{$_POST['par2']}.pdf"; require_once 'Classes/PHPExcel.php'; $rendererName = PHPExcel_Settings::PDF_RENDERER_TCPDF; $rendererLibrary = 'tcPDF.php'; $rendererLibraryPath = 'Classes/PHPExcel/Writer/PDF/'. $rendererLibrary; $inputFileType = PHPExcel_IOFactory::identify($newname); $objReader = PHPExcel_IOFactory::createReader($inputFileType); $objPHPExcel = $objReader->load($newname); $objPHPExcel->setActiveSheetIndex(0); 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'); } header('Content-Type: application/pdf'); header('Content-Disposition: attachment;filename="converted.pdf"'); header('Cache-Control: max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF'); $objWriter->save('php://output'); exit; } else { echo "Error!"; } 

0