我正在尝试在Laravel的Dompdf中使用OLD English字体。我已经将字体插入到Laravel视图中。但是,当生成PDF时似乎没有起作用。我尝试编辑dompdf >vendor >.../dompdf_font_family_cache.dist.php
文件,但没有运气。
有人能建议一个解决方案吗?
提前感谢。
利用 Laravel 提供的 storage_path 方法,在视图/HTML 中添加 @font-face 规则。
@font-face {
font-family: 'Your custom font name';
src: url({{ storage_path('fonts\your-custom-font.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
}
在你的 CSS 中添加如下所示的字体族规则
body {
font-family: "Your custom font name";
}
希望这能有所帮助。
$options->set('chroot', storage_path());
- waffl*
(换行)
!.gitignore
- Patrick Schmidtfont-family
不包含空格,否则由于某些原因可能无法正常工作。 - NoOorZ24我也尝试了添加自定义字体。我在视图中添加了字体(使用@font-face声明),但是当我尝试生成pdf时,它会在AdobeFontMetrics.php中给我一个ErrorException。 我通过在laravel项目的storage文件夹中创建一个字体文件夹来解决这个问题。 现在我的目录结构如下:
> storage
> app
> fonts
> framework
> logs
我希望这能有所帮助
将字体文件放置在storage/fonts
文件夹中。
例如,我的OpenSans字体文件存储在storage/fonts/
文件夹中。
你也可以从GoogleFonts下载Open Sans字体文件。
最后,在HTML文件中添加以下样式标签即可。
<style>
@font-face {
font-family: 'Open Sans';
src: url({{ storage_path("fonts/static/OpenSans/OpenSans-Bold.ttf") }}) format("truetype");
font-weight: 700;
font-style: normal;
}
@font-face {
font-family: 'Open Sans';
src: url({{ storage_path("fonts/static/OpenSans/OpenSans-BoldItalic.ttf") }}) format("truetype");
font-weight: 700;
font-style: italic;
}
@font-face {
font-family: 'Open Sans';
src: url({{ storage_path("fonts/static/OpenSans/OpenSans-ExtraBold.ttf") }}) format("truetype");
font-weight: 800;
font-style: normal;
}
@font-face {
font-family: 'Open Sans';
src: url({{ storage_path("fonts/static/OpenSans/OpenSans-ExtraBoldItalic.ttf") }}) format("truetype");
font-weight: 800;
font-style: italic;
}
@font-face {
font-family: 'Open Sans';
src: url({{ storage_path("fonts/static/OpenSans/OpenSans-Light.ttf") }}) format("truetype");
font-weight: 300;
font-style: normal;
}
@font-face {
font-family: 'Open Sans';
src: url({{ storage_path("fonts/static/OpenSans/OpenSans-LightItalic.ttf") }}) format("truetype");
font-weight: 300;
font-style: italic;
}
@font-face {
font-family: 'Open Sans';
src: url({{ storage_path("fonts/static/OpenSans/OpenSans-Medium.ttf") }}) format("truetype");
font-weight: 500;
font-style: normal;
}
@font-face {
font-family: 'Open Sans';
src: url({{ storage_path("fonts/static/OpenSans/OpenSans-MediumItalic.ttf") }}) format("truetype");
font-weight: 500;
font-style: italic;
}
@font-face {
font-family: 'Open Sans';
src: url({{ storage_path("fonts/static/OpenSans/OpenSans-Regular.ttf") }}) format("truetype");
font-weight: 400;
font-style: normal;
}
@font-face {
font-family: 'Open Sans';
src: url({{ storage_path("fonts/static/OpenSans/OpenSans-SemiBold.ttf") }}) format("truetype");
font-weight: 600;
font-style: normal;
}
@font-face {
font-family: 'Open Sans';
src: url({{ storage_path("fonts/static/OpenSans/OpenSans-SemiBoldItalic.ttf") }}) format("truetype");
font-weight: 600;
font-style: italic;
}
@font-face {
font-family: 'Open Sans';
src: url({{ storage_path("fonts/static/OpenSans/OpenSans-Italic.ttf") }}) format("truetype");
font-weight: 400;
font-style: italic;
}
body {
font-family: 'Open Sans', sans-serif;
}
</style>
@font-face {
font-family: 'Journal';
src: url('yourwebsite.com/journal.ttf")}}') format('truetype');
}
.typed {
font-family: 'Journal';
}
<p class='typed'>Signature</p>
Set font into html page which is load in Dompdf
<html>
<head>
<style>
@font-face {
font-family: 'Helvetica';
font-weight: normal;
font-style: normal;
font-variant: normal;
src: url("font url");
}
body {
font-family: Helvetica, sans-serif;
}
</style>
</head>
<body>
<p>hello world</p>
</body>
</html>
@font-face
声明。你在评论中指出你已经尝试过这个...你应该更新你的问题,以便我们可以看到你尝试了什么。正在运行的进程是否具有对存储/字体目录的读写访问权限,这是laravel-dompdf的默认设置(参考)? - BrianS