mPDF使用动态HTML模板生成多个PDF循环

时间:2019-11-15 20:26:20

标签: php mpdf output-buffering

我正在尝试使用接受引号id的动态html模板生成多个引号。遍历id时,将生成第一个PDF,然后由于以下错误而失败...

“ PHP致命错误:在第22行的/home/eepherg/public_html/mobiquote1.2/followups.php中,在null上调用成员函数fetch()”

似乎包含是问题所在,如果我将其从循环中删除,则会创建多个空白PDF。我如何在输出模板中多次包含动态模板...这是我的代码,对您的帮助将不胜感激。

<?php

include($_SERVER['DOCUMENT_ROOT'] . "/mpdf/mpdf.php");

require ("/home/eepherg/cnct_mobiquote.php");

try {
        $sql = "SELECT 
                    a.headersid, 
                    c.email,
                    a.ref,
                    a.description,
                    c.clientname,
                    d.doc_template
                 FROM `headers` a 
                 JOIN `users` b ON a.userid = b.userid
                 JOIN `clients` c ON a.clientid = c.clientid
                 JOIN companies d ON a.companyid = d.companyid
                 WHERE a.follow_up_1 = CURRENT_DATE AND a.status = 2 AND a.active = 1"; //only incomplete and emailed quotes
        $stmt = $conn->prepare($sql);
        $stmt->execute();
            while ($row = $stmt->fetch(PDO::FETCH_NUM)) {

                    $quoteid = $row[0];
                    $email = $row[1];
                    $quote_ref = $row[2];
                    $description = $row[3];
                    $client = $row[3];
                    $quote_template = $row[5];

                    //-- generate the .pdf 

                        //set the path for the temp pdf
                        $savedtemppdf = $_SERVER['DOCUMENT_ROOT'] . "/mobiquote1.2/temp_pdf/".$quote_ref.".pdf";

                        $mpdf=new mPDF('c','A4','','',20,15,30,25,10,10);
                        $mpdf->SetDisplayMode('fullpage');
                        $mpdf->list_indent_first_level = 0;  // 1 or 0 - whether to indent the first level of a list

                        $mpdf->setAutoBottomMargin = 'stretch';
                        $mpdf->SetHTMLFooter('');

                        ob_start( );
                        include($_SERVER['DOCUMENT_ROOT'] . "/mobiquote1.2/templates/".$quote_template.".php?id=".$quoteid);
                        $output = ob_get_clean( );
                        ob_end_clean();

                        $mpdf->WriteHTML($output);
                        $mpdf->Output($savedtemppdf,'F');

                    //email the quote with attachment
            }
}

catch(PDOException $e){
    echo 'Error: ' . "<br />" . $sql . "<br />" . $e->getMessage() . "<br />";
}

//close the connection
$stmt = null;
$conn = null; 

?>

0 个答案:

没有答案