【问题标题】:DOMPDF not caching some fontsDOMPDF 不缓存某些字体
【发布时间】:2017-03-16 11:17:50
【问题描述】:

我想在我的 PDF 中使用 5 种不同的字体(全部为 TrueType)。昨天我将其中一个添加为@font-face,并将文件复制到/storage/fonts(我使用的是barryvdh/laravel-dompdf,所以这是默认设置的)。 .ufm 已创建并添加到 dompdf_font_family_cache.php,一切正常。

今天我想添加其余的字体,我已经做了单独的@font-face 属性,复制了字体但没有创建 .ufm 文件,所以它们不能在 PDF 中使用。

Google 字体 可以毫无问题地添加,并且它们正在被缓存!

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <style>
            @page {
                margin:0;
                padding:0;
            }
            @font-face {
                font-family: 'font1';
                src: url('/storage/fonts/font1.ttf') format('truetype');
                font-weight: normal;
                font-style: normal;
            }
            @font-face {
                font-family: 'font2';
                src: url('/storage/fonts/font2.ttf') format('truetype');
                font-weight: normal;
                font-style: normal;
            }
            .font1{
                text-align: center;
                font-family: 'font1', sans-serif;
            }
            .font2{
                font-family: 'font2', sans-serif;
                text-align: center;
            }
        </style>
    </head>
    <body>
        <div id="container">
            <div class="font1">This font is cached</div>
            <div class="font2">This font isn't</div>
        </div>
    </body>
</html>

我在本地 WAMP 服务器 (PHP 5.6.25)、Laravel 5.3、DOMPDF 0.8 w/ laravel-dompdf 上。

我错过了什么?

【问题讨论】:

    标签: php laravel pdf dompdf


    【解决方案1】:

    删除storage\fonts中的所有文件

    授予 DOMPDF 在那里创建字体的权限

    sudo chmod -R 755 storage/fonts
    

    创建一个新的 pdf 以重新生成字体。

    【讨论】:

    • 好吧,你让我走上了正轨。我从/storage/fonts 目录中删除了所有内容,将文件放在public 目录中,并在@font-face 中调用这些URL。所有字体都已缓存并准备就绪,现在我了解它是如何工作的。 :) 感谢您的帮助!
    • 没问题,很高兴它帮助了你!
    • 你好@João,我也试过了,但是我添加的新字体没有缓存在 storage/fonts 目录中。我已将新字体放在 public/fonts 目录中,并将其包含在 PDF 视图文件中并创建了一个新的 PDF,但它仍然没有缓存在存储中。我正在使用 laravel 5.5,你能帮我解决这个问题吗?
    • 您是否尝试将字体手动放入 storage/fonts 并重新生成 PDF?
    • 你应该试试上面的评论,或者简单地尝试从一些cdn中引用字体。像这样:&lt;link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet"&gt;
    猜你喜欢
    • 1970-01-01
    • 2011-08-21
    • 2017-12-17
    • 2011-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-18
    • 2012-02-11
    相关资源
    最近更新 更多