调用未定义的方法Barryvdh \ DomPDF \ PDF :: setOptions()(laravel 5.3)

时间:2016-12-23 22:51:33

标签: php laravel pdf laravel-5.3 dompdf

我遵循:How to get page number on dompdf PDF when using "view"

我添加$pdf->setOptions('isPhpEnabled', true);是这样的:

public function listdata()
{
    $data = User::all();

    $pdf=PDF::loadView('print_tests.test_pdf', ['data' => $data]);
    $pdf->setOptions('isPhpEnabled', true);
    $pdf->setPaper('L', 'landscape');
    return $pdf->stream('test_pdf.pdf');
}

在正文(视图)中我添加如下:

<script type="text/php">
    if ( isset($pdf) ) {
        $x = 72;
        $y = 18;
        $text = "{PAGE_NUM} of {PAGE_COUNT}";
        $font = $fontMetrics->get_font("helvetica", "bold");
        $size = 6;
        $color = array(255,0,0);
        $word_space = 0.0;  //  default
        $char_space = 0.0;  //  default
        $angle = 0.0;   //  default
        $pdf->page_text($x, $y, $text, $font, $size, $color, $word_space, $char_space, $angle);
    }
</script>

存在这样的错误:

FatalThrowableError in PrintTestController.php line 21: Call to undefined method Barryvdh\DomPDF\PDF::setOptions()

我尝试改变,好像是:$pdf->set_options('isPhpEnabled', true);

它也不起作用

注意:

我使用barryvdh / laravel-dompdf“:”^ 0.7.0“(v0.7)

有没有人可以帮助我?

更新

我再试一次:

use Dompdf\Dompdf;

public function listdata()
{
    $data = User::all();

    $pdf = new Dompdf();
    $pdf->set_option("isPhpEnabled", true);

    $pdf=PDF::loadView('print_tests.test_pdf', ['data' => $data]);
    $pdf->setPaper('L', 'landscape');
    return $pdf->stream('test_pdf.pdf');
}

没有错误,但页码不可见

1 个答案:

答案 0 :(得分:0)

您可能希望停止使用3个半年前的问题和答案,并开始使用documentation provided by the developer

您可能正在寻找一个功能Dompdf::set_option()