Php Laravel DomPDF谷歌字体未加载
尝试在Laravel DomPDF 0.7*中使用Google字体,但我很难让它们显示出来。事实上,我无法使用任何自定义字体,不仅仅是谷歌字体Php Laravel DomPDF谷歌字体未加载,php,laravel,dompdf,Php,Laravel,Dompdf,尝试在Laravel DomPDF 0.7*中使用Google字体,但我很难让它们显示出来。事实上,我无法使用任何自定义字体,不仅仅是谷歌字体 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Ty
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="https://fonts.googleapis.com/css?family=Caveat" rel="stylesheet">
<style type="text/css">
.signature {
font-family: 'Caveat', cursive !important;
font-size: 30px;
}
</style>
</head>
<body>
<p class="signature">Name</p>
</body>
</html>
以下是控制器代码:
public function download(Request $request, string $contractKey)
{
$item = Item::findOrFail($contractKey);
$body = @$item->contract;
$pdf = PDF::loadView('pdf.contract', [
'body' => $this->cleanContract($body),
'docId' => md5($item->id),
'item' => $item,
'ip' => $ip = @$request->ips()[1] ?: $request->ip(),
]);
$pdf->output();
$dom_pdf = $pdf->getDomPDF();
$canvas = $dom_pdf->get_canvas();
$canvas->page_text($canvas->get_width() - 70, $canvas->get_height() - 30, "Page {PAGE_NUM} of {PAGE_COUNT}", null, 10, [0, 0, 0]);
return $pdf->stream();
}
字体位置答案
我只能通过在服务器上安装字体来实现这一点
你需要告诉DomPDF字体在哪里
public function download(Request $request, string $contractKey)
{
$item = Item::findOrFail($contractKey);
$body = @$item->contract;
$pdf = PDF::loadView('pdf.contract', [
'body' => $this->cleanContract($body),
'docId' => md5($item->id),
'item' => $item,
'ip' => $ip = @$request->ips()[1] ?: $request->ip(),
]);
$pdf->output();
$dom_pdf = $pdf->getDomPDF();
// set font dir here
$dom_pdf->set_option('font_dir', storage_path('fonts/'));
$canvas = $dom_pdf->get_canvas();
$canvas->page_text(
$canvas->get_width() - 70,
$canvas->get_height() - 30,
"Page {PAGE_NUM} of {PAGE_COUNT}", null, 10, [0, 0, 0]);
return $pdf->stream();
}
将字体下载到存储器/font
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
.signature {
font-family: 'Caveat', cursive;
font-size: 30px;
}
</style>
</head>
<body>
<p class="signature">Name</p>
</body>
</html>
请尝试此
字母间距:1px代码>在处签名
CSS@Quỳ恩古伊ễn字体不对,字母间距不是问题。您可以尝试更新到最新版本,看看是否可以解决问题。当前版本是0.8.0
你能添加你的控制器代码吗?@whoacowboy添加了它不确定为什么会出现语法错误,但这也不是问题所在。同样的问题。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
.signature {
font-family: 'Caveat', cursive;
font-size: 30px;
}
</style>
</head>
<body>
<p class="signature">Name</p>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="https://fonts.googleapis.com/css?family=Caveat" rel="stylesheet">
<style type="text/css">
.signature {
font-family: 'Caveat', cursive;
font-size: 30px;
}
</style>
</head>
<body>
<p class="signature">Name</p>
</body>
</html>