gpt4 book ai didi

php - 如何在 laravel dompdf 中自定义字体和页面?

转载 作者:行者123 更新时间:2023-12-04 12:47:15 55 4
gpt4 key购买 nike

我从这里得到:https://github.com/barryvdh/laravel-dompdf

我的 Controller 是这样的:

public function listdata()
{
$pdf=PDF::loadView('print_tests.test_pdf');
$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("Arial", "bold");
$size = 6;
$color = array(0,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>

我用这个:

"barryvdh/laravel-dompdf": "^0.7.0",

执行时,字体不是宋体,页面不显示。

我该如何解决?

最佳答案

laravel 5.5 above 中尝试。

1.首先下载你想要添加(或设置)为.ttf扩展名的字体

2.像这样在 laravel 存储文件夹中存储 storage/fonts/yourfont.ttf

3.在 Blade 中使用 CSS @font-face 规则..

4.例如创建这样的sample.blade.php文件

<html>
<head>
<meta http-equiv="Content-Type" content="charset=utf-8" />
<style type="text/css">
@font-face {
font-family: 'yourfont'; //you can set your custom name also here..
src: url({{ storage_path('fonts/yourfont.ttf') }}) format('truetype');
font-weight: 400; // use the matching font-weight here ( 100, 200, 300, 400, etc).
font-style: normal; // use the matching font-style here
}
body{
font-family: "yourfont", //set your font name u can set custom font name also which u set in @font-face css rule
</style>
</head>
<body>
Check your font is working or not...
</body>
</html>

关于php - 如何在 laravel dompdf 中自定义字体和页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43721078/

55 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com