Failed to load PDF document

4

I'm working with an office system, where the user will enter the legal number, the person to which the document will be directed and the message, and would like that, if the data were successfully added to the bank, a PDF with the information entered would be generated through the DOMPDF library. However, when executing, the following error is returned: "Failed to load PDF document". The code is this:

<?php
    include_once("../conexao.php");

    $numero = $_POST["numero"];
    $interessado = $_POST["interessado"];
    $assunto = $_POST["assunto"];       

    $query = mysqli_query($conexao, "INSERT INTO oficio VALUES ('$numero','$interessado','$assunto');");

    use Dompdf\Dompdf;
    require_once ("../dompdf/autoload.inc.php");

    if(mysqli_affected_rows($conexao) != 0){
        $html = "<p>".$numero."</p>";
        $html .= "<p>".$interessado."</p>";
        $html .= "<p>".$assunto."</p>";

        $dompdf = new DOMPDF();
        //echo $html;

        $dompdf->load_html("<h1 style='text-align: center;'>Teste - Gerar PDF</h1>".$html);
        $dompdf->render();
        $dompdf->stream("teste_pdf.pdf",array("Attachment" => false));
    }
    else{
        echo "<META HTTP-EQUIV=REFRESH CONTENT = '0;URL=http://localhost/principal.php?link=01'>
                <script type=\"text/javascript\">
                    alert(\"Não foi possível realizar a abertura do ofício!\");
                </script>";
    }
?>

What could be done for the document to be created?

    
asked by anonymous 13.09.2017 / 17:11

1 answer

1

I have two suggestions:

  • First try to see what charset of the text that comes from your database, it may be that in the database you are using ISO-8859-1 and the user-lib DOMPDF UTF-8
  • The documentation for this lib says that malformed HTML can cause a problem (check if it has no tag without closing, or using invalid attributes) ( link ).
01.08.2018 / 18:08