Error when trying to create a PDF file with PHP and the FPDF library
Fatal error: Uncaught Exception: FPDF error: Some data has already been output, can't send PDF file (output started at C:\xampp\htdocs\paginaoctago\temp\lev_6\ord_com.php:68) in C:\xampp \htdocs\paginaoctago\temp\lev_6\fpdf\fpdf.php:271 Stack trace: 0 C:\xampp\htdocs\paginaoctago\temp\lev_6\fpdf\fpdf.php(1052): FPDF->Error('Some data has a...') #1 C:\xampp\htdocs\paginaoctago\temp\lev_6\fpdf\fpdf.php(999): FPDF->_checkoutput() #2 C:\xampp\htdocs\paginaoctago\temp\ lev_6\ord_com.php(538): FPDF->Output() #3 {main} thrown in C:\xampp\htdocs\paginaoctago\temp\lev_6\fpdf\fpdf.php on line 271
The code is the following:
<body>
<script src="js/main.js">
</script>
<script src="consultas.js">
</script>
<script src="funciones_de_ord_comp.js">
</script>
<?php
require('fpdf/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'¡Hola, Mundo!');
$pdf->Output();
?>
</body>
The solution was to remove all visual HTML output by creating a separate PHP file just to display the PDF.
To save without showing it can be used by placing the parameters of the file name in the output
If desired, variables can be used, such as