在我的laravel项目中,我使用DOMPDF从htmlBlade 文件生成pdf.我想按语言 Select 显示印地语或古吉拉特语文本.这是我的控制器代码.

 $pdf=PDF::loadView('my-htmlt.pdffile',['header'=>$header,'data'=>$data,'footer'=>$footer]);        
    $name=$header->name."_".date('YmdHis');

    if(isset($view) && $view!=''){
        return $pdf->stream($name.'.pdf');
    } else {
        return $pdf->download($name.'.pdf');
    }

以下是Blade 文件中的代码.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>{{$header->name}}</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<style type="text/css">
    @page{
        padding: 15px;
    }
    <?php if($header->lang== 'Guj'){ ?> 
    * {
        font-family: 'noto serif gujarati', sans-serif;
      }
    <?php } else if($header->lang == 'Hindi'){ ?>
    * { 
        font-family: 'tiro devanagari hindi', sans-serif; 
      }
    <?php } ?>
   </style>
   <body>{{Content fetched from database either in Hindi or Gujarati}}</body>
</html>

I have downloaded ttf font files for Noto Serif Gujarati and Tiro Devnagari and copy under projectfolder/storage/fonts Folder. I have also tried using face font css with file path of ttf file. But result is same so, working with less code. I have set collation and charset as utf8_unicode_ci in database and getting text properly from database, tested printing html view. Now issue is that text is showing in Hindi or gujarati but text is not showing properly as per my requirement. For example I want to show text like "ચિત્ર જોઈ તેનો પહેલો મૂળાક્ષર શોધો". But it is showing like this enter image description here

Same way in hindi I want to show text like "कौन सा जीव धीमी गति से चलता है ?" But it is showing like this enter image description here

有没有人有办法在PDF中显示正确的文本?

推荐答案

所以,在付出了很多努力之后,我 Select 了另一种 Select .我用以下方式呈现我的观点

return view('my-html.pdffile',['header'=>$header,'data'=>$data,'footer'=>$footer]);

在我的-html.pdffileBlade 文件中,我允许用户使用window.print脚本下载pdf,如下所示.

<script>
var is_chrome = function () { return Boolean(window.chrome); }
if(is_chrome){
    window.print();
    //  setTimeout(function(){window.close();}, 10000);
    //  give them 10 seconds to print, then close
}else{
    window.print();
}
</script>

现在我可以根据我的要求下载所有语言的pdf,而不需要使用任何字体或下载任何字体库.

Laravel相关问答推荐

Laravel-如何按第三表关系对数据进行分类

在Laravel Sail Docker环境中的PHPMyAdmin中出现`Out of Memory‘错误

Laravel FAKER语法

spatie 包 laravel-tags 在迁移中没有 down() 函数是有原因的吗

未找到 apiResource 404 中的变量

从 Laravel 中的值开始主键

使用枢轴插入多对多时的Laravel问题

如何通过 Controller 访问 Laravel 中 Model 的值?

Laravel 从 5.1 升级到 5.2.0 错误

在 laravel 4.2 中,用户 'root'@'localhost' 的 Laravel 访问被拒绝(使用密码:YES)

你如何找到 Laravel 外观背后的底层类?

控制器中的 Laravel Auth 用户 ID

Laravel 框架类在 PHPUnit 数据提供程序中不可用

Laravel Electron邮件验证模板位置

在表单中添加一对多 - Backpack laravel

未定义的类常量App\Providers\RouteServiceProvider::HOME

如何更改 Handlebars.js 的默认分隔符?

将图标添加到 Laravelcollective 提交按钮

如何在 Laravel 中动态更改 .env 文件中的变量?

在哪里放置 Blade::extend