Problem generating PDF in DOMPDF

1

I'm having problems generating a pdf from php with DOMPDF.

This is the error that gives me

  

Uncaught exception 'Dompdf \ Exception' with message 'No block-level parent found.

And this is the code I use:

require_once 'dompdf/autoload.inc.php';
use Dompdf\Dompdf;
// instantiate and use the dompdf class

$dompdf = new Dompdf();
$file=file_get_contents('resultados.php');
$dompdf->load_html($file);

// (Optional) Setup the paper size and orientation
$dompdf->set_paper('A4', 'landscape');

// Render the HTML as PDF
$dompdf->render();

// Output the generated PDF to Browser
$dompdf->stream('document.pdf');
echo $file;?>

I have done a print of $ file and I have observed that file_get_contents () does not process the variables. I think that there may be the error. Does anyone know any way to solve this?

Thanks in advance

    
asked by RafaelM 12.12.2016 в 12:20
source

1 answer

1

Considering that the redirects are fine and that the .php file what it does is render the view to create the structure we can do this:

<?php
require_once 'dompdf/autoload.inc.php';
use Dompdf\Dompdf;
$dompdf = new Dompdf();

ob_start(); //iniciamos un output buffer
require_once('resultados.php'); // llamamos el archivo que se supone contiene el html y dejamoso que se renderize
$dompdf->load_html(ob_get_clean());//y ponemos todo lo que se capturo con ob_start() para que sea capturado por DOMPDF

$dompdf->set_paper('A4', 'landscape');
$dompdf->render();
$dompdf->stream('document.pdf');
?>

Any questions do not hesitate to comment

    
answered by 15.03.2017 в 03:01