dongzheng4556 2017-03-16 11:17
浏览 136
已采纳

DOMPDF没有缓存某些字体

I want to use 5 different fonts in my PDF (all of them TrueType). Yesterday I added one of them as @font-face and copied the file to /storage/fonts (I am using barryvdh/laravel-dompdf, so this is set by default). The .ufm was created and added to dompdf_font_family_cache.php, everything worked fine.

Today I wanted to add the rest of the fonts, I have made separate @font-face properties, copied the fonts but no .ufm files were created, so they can't be used in the PDF.

Google Fonts can be added without any problem, and they are getting cached!

<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>

I am on a local WAMP server (PHP 5.6.25), Laravel 5.3, DOMPDF 0.8 w/ laravel-dompdf.

What am I missing?

  • 写回答

1条回答 默认 最新

  • doudong3570 2017-03-16 11:50
    关注

    Delete all files in the storage\fonts

    Give permission to DOMPDF to create fonts there

    sudo chmod -R 755 storage/fonts
    

    Create a new pdf to regenerate the fonts.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看