php dompdf load_html方法返回Null

cidc1ykv  于 12个月前  发布在  PHP
关注(0)|答案(2)|浏览(103)

你好,我在其他项目中使用了dompdf,它工作得很好,这次我没有生成pdf,load_html函数返回null,我的ide告诉我:

Method 'load_html' is deprecated

下面是我写的代码:

use Dompdf\Dompdf;

    $dompdf = new DOMPDF();

    $dompdf->set_option('isHtml5ParserEnabled', true);

    $html = str_replace(
        array(
            '{{DOCUMENT}}',
            '{{DATE}}',
            '{{TITLE}}',
            '{{USER_FIRSTNAME}}',
            '{{USER_LASTNAME}}',
            '{{SPECIALITY}}',
            '{{DESC}}',
            '{{PATIENT_FIRSTNAME}}',
            '{{PATIENT_LASTNAME}}',
            '{{INVOICE_NUMBER}}',
            '{{PRICE}}',
            '{{PRICE_TTC}}',
            ' class="no-tva"'
        ),
        array(
            'Facture',
            date('d/m/Y'),
            $_SESSION['cabinet_data_user']['infos']['title'],
            substr($_SESSION['cabinet_data_user']['infos']['firstname'], 0, 1).'.',
            $_SESSION['cabinet_data_user']['infos']['lastname'],
            $_SESSION['cabinet_data_user']['infos']['speciality'],
            $_user_desc,
            ucfirst(mb_strtolower($invoice_pdf['firstname'])),
            ucfirst(mb_strtolower($invoice_pdf['lastname'])),
            isset($invoice_pdf['id']) ? $invoice_pdf['id'] : '123456',
            number_format($invoice_pdf['price'], 2, ',', '.'),
            ($invoice_pdf['tva']) ?
                number_format($invoice_pdf['price'] + $invoice_pdf['price'] * $invoice_pdf['tva'], 2, ',', '.') :
                number_format($invoice_pdf['price'], 2, ',', '.'),
            $invoice_pdf['tva'] ? '' : ' class="no-tva"'
        ),
        file_get_contents(BASE.'params/templates/invoice.html')
    );

    unset($_user_desc);

    $dompdf->load_html($html);
    $dompdf->setPaper('A4', 'portrait');
    $dompdf->render();

任何建议都可以帮助,谢谢。

fnx2tebb

fnx2tebb1#

我升级到PHP7.3就解决了

disho6za

disho6za2#

// https://github.com/dompdf/dompdf

use Dompdf\Dompdf;    // reference the Dompdf namespace

$dompdf = new Dompdf();    // instantiate and use the dompdf class
$dompdf->loadHtml('hello world');

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

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

$dompdf->stream();    // Output the generated PDF to Browser

相关问题