Dompdf-> render (); doesn't work in api class

I have a problem while trying to render html to pdf using dompdf.

I have a code placed inside a class and after the procedure code I would like it to create a pdf html file.

This is the code I have at the moment:

$templatefile = file_get_contents("templates/costreport.htm");
//fill headers
$templatefile = str_replace("%DATES%",stripslashes($startdate)." - ".stripslashes($enddate),$templatefile);     

if ($siteid>0) {
    $pdfname = "costreport-".$clientid.".pdf";
} else {
    $pdfname = "costreport-".$clientid."-".$siteid.".pdf";
//insert into database
//Close and output PDF document
$pdfname = str_replace("/","-",$pdfname);
$pdfname = str_replace("\\","-",$pdfname);
//create pdf
// unregister Yii autoloader
// register dompdf autoloader
// register Yii autoloader again
$dompdf = new DOMPDF();
$pdf = $dompdf->output();
// You can now write $pdf to disk, store it in a database or stream it
// to the folder.
file_put_contents('../tmp/'.$clientid.'/'.$pdfname, $pdf);  


The code doesn't work when dompdf-> render (); is located, but as soon as I take that line, the code works and the file is created, but I cannot open it if it is not displayed.

I've tried debugging the code and made the HTML template valid, but I'm at a loss now.

The error I am returning is just boolen false

when I run the script with dompdf->render();

in it.


source to share

1 answer

The problem was that I had this piece of code at the top of my class.

/set up path to new dir including dir to be created
            $newdirpath = getcwd()."/".$clientid;
            //if an old invoice ticket pack exists unlink it so as not to get things confused with the new pack being created.
            if (file_exists(getcwd()."/$clientid_$siteid_CostReport.pdf")) {
            //setup temp dir
            if (!is_dir($newdirpath)) {
                //create new dir if it doesn't already exist!
            } else {
                //dir already exists we need to empty it out first incase there old stuff in there we don't want to duplicate data




All Articles