启用字体子设置时,laravel-dompdf得到错误“未定义索引:glyf”

问题描述

我正在尝试使用pdf库生成laravel-dompdf文件。

这是我使用的字体样式:

        @font-face {
            font-family: 'Hiragino Sans';
            src: url('fonts/Hiragino Sans GB W3.ttf') format('truetype');
            font-weight: normal;
        }
        @font-face {
            font-family: 'Hiragino Sans';
            src: url('fonts/Hiragino Sans GB W6.ttf') format('truetype');
            font-weight: bold;
        }

这是控制器中的代码:

return PDF::loadView('pdf.presaleorder')->save('test.pdf');

一切正常,但是生成的pdf文件太大,大于20MB。我发现可以通过将enable_font_subsetting中的config/dompdf.php字段更改为true来减小它的大小。

但是当我生成pdf文件时,它引发了错误:

 ErrorException  : Undefined index: glyf

  at G:\Project\Laravel\EventPayment\vendor\phenx\php-font-lib\src\FontLib\TrueType\File.php:329
    325|    *
    326|    * @return Table
    327|    */
    328|   public function getTableObject($name) {
  > 329|     return $this->data[$name];
    330|   }
    331| 
    332|   public function setTableObject($name,Table $data) {

  1   Illuminate\Foundation\Bootstrap\HandleExceptions::handleError("Undefined index: glyf","G::\Project\Laravel\EventPayment\vendor\phenx\php-font-lib\src\FontLib\TrueType\File.php",["glyf]"])
      G:\Project\Laravel\EventPayment\vendor\phenx\php-font-lib\src\FontLib\TrueType\File.php:32\Project\29                                                                                                
                                                                                                9        
  2   FontLib\TrueType\File::getTableObject("glyf")
      G:\Project\Laravel\EventPayment\vendor\phenx\php-font-lib\src\FontLib\TrueType\File.php:2001                                                                                              1        

  Please use the argument -v to see more details.

当我添加参数-v时,显示了更多的跟踪错误

 2   FontLib\TrueType\File::getTableObject("glyf")
      G:\Project\Laravel\EventPayment\vendor\phenx\php-font-lib\src\FontLib\TrueType\File.php:201

  3   FontLib\TrueType\File::setSubset()
      G:\Project\Laravel\EventPayment\vendor\dompdf\dompdf\lib\Cpdf.php:1171

  4   Dompdf\Cpdf::processFont()
      G:\Project\Laravel\EventPayment\vendor\dompdf\dompdf\lib\Cpdf.php:931

  5   Dompdf\Cpdf::o_font("add")
      G:\Project\Laravel\EventPayment\vendor\dompdf\dompdf\lib\Cpdf.php:3196

  6   Dompdf\Cpdf::output()
      G:\Project\Laravel\EventPayment\vendor\dompdf\dompdf\src\Adapter\CPDF.php:1213

  7   Dompdf\Adapter\CPDF::output([])
      G:\Project\Laravel\EventPayment\vendor\dompdf\dompdf\src\Dompdf.php:932

  8   Dompdf\Dompdf::output()
      G:\Project\Laravel\EventPayment\vendor\barryvdh\laravel-dompdf\src\PDF.php:157

  9   Barryvdh\DomPDF\PDF::output()
      G:\Project\Laravel\EventPayment\vendor\barryvdh\laravel-dompdf\src\PDF.php:167

  10  Barryvdh\DomPDF\PDF::save("test.pdf")
      G:\Project\Laravel\EventPayment\app\Services\OrderService.php:2170

  11  App\Services\OrderService::createOrderPdf()
      G:\Project\Laravel\EventPayment\app\Console\Commands\CreateOrderPdf.php:41

  12  App\Console\Commands\CreateOrderPdf::handle(Object(App\Services\OrderService))
      G:\Project\Laravel\EventPayment\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:32

  13  call_user_func_array()
      G:\Project\Laravel\EventPayment\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:32

  14  Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
      G:\Project\Laravel\EventPayment\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:90

  15  Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application),Object(Closure))
      G:\Project\Laravel\EventPayment\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:34

  16  Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application),[])    
      G:\Project\Laravel\EventPayment\vendor\laravel\framework\src\Illuminate\Container\Container.php:576

  17  Illuminate\Container\Container::call()
      G:\Project\Laravel\EventPayment\vendor\laravel\framework\src\Illuminate\Console\Command.php:183

  18  Illuminate\Console\Command::execute(Object(Symfony\Component\Console\Input\ArgvInput),Object(Illuminate\Console\OutputStyle))
      G:\Project\Laravel\EventPayment\vendor\symfony\console\Command\Command.php:255

  19  Symfony\Component\Console\Command\Command::run(Object(Symfony\Component\Console\Input\ArgvInput),Object(Illuminate\Console\OutputStyle))
      G:\Project\Laravel\EventPayment\vendor\laravel\framework\src\Illuminate\Console\Command.php:170

  20  Illuminate\Console\Command::run(Object(Symfony\Component\Console\Input\ArgvInput),Object(Symfony\Component\Console\Output\ConsoleOutput))
      G:\Project\Laravel\EventPayment\vendor\symfony\console\Application.php:1000

  21  Symfony\Component\Console\Application::doRunCommand(Object(App\Console\Commands\CreateOrderPdf),Object(Symfony\Component\Console\Input\ArgvInput),Object(Symfony\Component\Console\Output\ConsoleOutput))
      G:\Project\Laravel\EventPayment\vendor\symfony\console\Application.php:271

  22  Symfony\Component\Console\Application::doRun(Object(Symfony\Component\Console\Input\ArgvInput),Object(Symfony\Component\Console\Output\ConsoleOutput))
      G:\Project\Laravel\EventPayment\vendor\symfony\console\Application.php:147

  23  Symfony\Component\Console\Application::run(Object(Symfony\Component\Console\Input\ArgvInput),Object(Symfony\Component\Console\Output\ConsoleOutput))
      G:\Project\Laravel\EventPayment\vendor\laravel\framework\src\Illuminate\Console\Application.php:90

  24  Illuminate\Console\Application::run(Object(Symfony\Component\Console\Input\ArgvInput),Object(Symfony\Component\Console\Output\ConsoleOutput))
      G:\Project\Laravel\EventPayment\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php:133

  25  Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput),Object(Symfony\Component\Console\Output\ConsoleOutput))
      G:\Project\Laravel\EventPayment\artisan:37

有人解决吗?

我正在使用

laravel: 5.8
barryvdh/laravel-dompdf: 0.8.7
dompdf/dompdf: 0.8
windows 10

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...