When I add HTML it gives header error

Page :

<?php

     header("Content-Type: text/html; charset=utf-8"); 

?>

<html>

    <head>

        <title>Gceu IMW Muriaé - São Cristóvão </title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    </head>

    <body>

        <?php 

            require_once "../_scripts/_php/_configuracoes/erros.php";
            require_once "fpd181/PDF.php";

            $html = "<div><h1>Hoje é o dia " . date( "Y-m-d" ) . "</h1></div>";

            $pdf = new PDF();
            $pdf->AddPage();
            $pdf->SetFont('Arial','B',16);
            $pdf->WriteHTML($html);
            $pdf->Output();

        ?>

    </body>

</html>

Is giving the following error:

Fatal error: Uncaught Exception: FPDF error: Some data has already been output, can't send PDF file in D:\Trabalhos\host\htdocs\wesleyanagceu.com.br\pdf\fpd181\fpdf.php:271 Stack trace: #0 D:\Trabalhos\host\htdocs\wesleyanagceu.com.br\pdf\fpd181\fpdf.php(1063): FPDF->Error('Some data has a...') #1 D:\Trabalhos\host\htdocs\wesleyanagceu.com.br\pdf\fpd181\fpdf.php(999): FPDF->_checkoutput() #2 D:\Trabalhos\host\htdocs\wesleyanagceu.com.br\pdf\pdf.php(29): FPDF->Output() #3 {main} thrown in D:\Trabalhos\host\htdocs\wesleyanagceu.com.br\pdf\fpd181\fpdf.php on line 271

But if I take out the HTML and leave only the PHP

    <?php

         header("Content-Type: text/html; charset=utf-8"); 

    ?>

<?php 

                require_once "../_scripts/_php/_configuracoes/erros.php";
                require_once "fpd181/PDF.php";

                $html = "<div><h1>Hoje é o dia " . date( "Y-m-d" ) . "</h1></div>";

                $pdf = new PDF();
                $pdf->AddPage();
                $pdf->SetFont('Arial','B',16);
                $pdf->WriteHTML($html);
                $pdf->Output();

            ?>

The some error and pdf displays. But with errors of accents.

Obs.: all involved files are UTF-8 unsigned Good

 0
Author: Carlos Rocha, 2019-02-08

1 answers

There can be no printout of the header for PDF creation by the library, even because there would be no reason to insert this code in the middle of the HTML structure, create a call to generate this file in another location or buffer your HTML so that it is printed after PDF.

 0
Author: Maike Oliveira, 2019-02-09 00:58:49