4
I am working with a crafts system, where the user will enter the number of the craft, the person to whom the document will be directed and the message, and would like that, if the data were successfully added to the database, a PDF with the information entered was generated, through the library DOMPDF. 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 to create the document?