<?php
//Configure the directory where you have the dompdf
require_once "dompdf/autoload.inc.php";
foreach($_GET  as $key => $value){${$key}=trim($value);$_PARAMS[$key]=${$key};}  
foreach($_POST as $key => $value){${$key}=trim($value);$_PARAMS[$key]=${$key};}

// use Dompdf\Dompdf; //para incluir el namespace de la librería
use Dompdf\Dompdf;
use Dompdf\Options;



$options = new Options();
$dompdf = new Dompdf($options);

$idnum=$idnum*1;
$idnum=str_pad($idnum,9,'0',STR_PAD_LEFT);
     
$file='../'.$empr.'/_doc/'.$docu.'_'.$idnum.'.html';
$file3='../'.$empr.'/_doc/'.$docu.'_'.$idnum.'.pdf';
$html=file_get_contents($file);

$options->set('isRemoteEnabled', TRUE);

// $dompdf->loadHtml('hello world');
$dompdf->loadHtml($html);
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'portrait');
// Render the HTML as PDF
$dompdf->render();


// Output the generated PDF to Browser
// $dompdf->stream();
if(empty($desti)){$desti=1;}


if($desti==1) //browser
{
header("Content-type: application/pdf");
header("Content-Disposition: inline; filename=".$file3);
echo $dompdf->output();
}

if($desti==2) // download
{
$dompdf->stream($docu.'_'.$idnum);
}     


if($desti==3)
{
$diskfile=$dompdf->output();
file_put_contents($file3,$diskfile);    
}





?>


