【发布时间】:2016-12-20 06:27:23
【问题描述】:
我加$pdf->set_option('isPhpEnabled', true);是这样的:
public function listdata()
{
$data = User::all();
$pdf=PDF::loadView('print_tests.test_pdf', ['data' => $data]);
$pdf->set_option('isPhpEnabled', true);
$pdf->setPaper('L', 'landscape');
return $pdf->stream('test_pdf.pdf');
}
在正文(视图)中,我这样添加:
<script type="text/php">
if ( isset($pdf) ) {
// OLD
// $font = Font_Metrics::get_font("helvetica", "bold");
// $pdf->page_text(72, 18, "{PAGE_NUM} of {PAGE_COUNT}", $font, 6, array(255,0,0));
// v.0.7.0 and greater
$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::set_option()
注意:
我使用 barryvdh/laravel-dompdf": "^0.7.0" (v0.7)
有没有人可以帮助我?
【问题讨论】:
-
@Ohgodwhy,我还是很困惑。这个:
$dompdf->set_option("isPhpEnabled", true);。它是放在控制器中还是放在哪里? -
没错。在运行时(目前你在控制器中的方式)很好。
-
@Ohgodwhy,但为什么仍然出错。看来我的代码是正确的
-
setOptions(),我想?而不是set_options() -
@Bagus Tesa,是一样的。它不工作
标签: php laravel pdf laravel-5.3 dompdf