当前位置:网站首页>laravel-dompdf导出pdf,中文乱码问题解决
laravel-dompdf导出pdf,中文乱码问题解决
2022-07-05 13:44:00 【深海之鲲】
composer安装dompdf包
composer require barryvdh/laravel-dompdf
发布配置文件,生成的配置文件config/dompdf.php,也可选择忽略此步骤
php artisan vendor:publish --provider="Barryvdh\DomPDF\ServiceProvider"
此处使用Facade导出,点击查看更多
use PDF;
$pdf = PDF::loadView('pdf.invoice', $data);
return $pdf->download('invoice.pdf');
dompdf包中没有unicode 中文编码的字体,在导出中文时会乱码。需要安装自定义中文字体。我选择的是msyh.ttf微软雅黑字体,该字体渲染后,导出的pdf文件会稍大,可自行选择其他字体。
下载php_font.php脚本,提取需要dompdf需要的字体,php_font工具脚本
- 首先将下载好的msyh.ttf字体下载到本地,粘贴到以下两个目录,一是laravel项目根目录,二是public目录下。php_font.php文件也复制到项目根目录。
在这里插入图片描述

- 执行命令提取msyh字体到dompdf中,以下是成功情况

- 需要注意storage目录下是否有fonts目录,如果没有本地可创建,这里在渲染pdf时,会生成字体缓存文件。(服务器上可能需要给storage/fonts/* 赋权限)
- 在blade文件中具体使用方式如下:
@font-face {
font-family: 'msyh';
font-style: normal;
font-weight: normal;
src: url(./msyh.TTF) format('truetype');
}
body {
font-family: 'msyh';
}
还需要注意,blade文件meta标签中必须是utf-8编码
操作全部完成,可以导出pdf了。
边栏推荐
- FPGA learning notes: vivado 2019.1 add IP MicroBlaze
- Personal component - message prompt
- 一网打尽异步神器CompletableFuture
- Operational research 68 | the latest impact factors in 2022 were officially released. Changes in journals in the field of rapid care
- RK3566添加LED
- Hide Chinese name
- Shandong University Summer Training - 20220620
- When there are too many input boxes such as input transmitted at one time in the form, the post data is intercepted
- 龙芯派2代烧写PMON和重装系统
- Go array and slice
猜你喜欢

Summit review | baowanda - an integrated data security protection system driven by compliance and security

嵌入式软件架构设计-消息交互

面试官灵魂拷问:为什么代码规范要求 SQL 语句不要过多的 join?

百度杯”CTF比赛 2017 二月场,Web:爆破-2

Self built shooting range 2022

法国学者:最优传输理论下对抗攻击可解释性探讨

What about data leakage? " Watson k'7 moves to eliminate security threats

Jasypt configuration file encryption | quick start | actual combat

French scholars: the explicability of counter attack under optimal transmission theory

Cloudcompare - point cloud slice
随机推荐
NFT value and white paper acquisition
Jetpack Compose入门到精通
搭建一个仪式感点满的网站,并内网穿透发布到公网 2/2
Go pointer
Cloudcompare - point cloud slice
A detailed explanation of ASCII code, Unicode and UTF-8
Network security HSRP protocol
Backup and restore of Android local SQLite database
Zibll theme external chain redirection go page beautification tutorial
Solve the problem of invalid uni app configuration page and tabbar
[notes of in-depth study paper]uctransnet: rethink the jumping connection in u-net from the perspective of transformer channel
这18个网站能让你的页面背景炫酷起来
The "Baidu Cup" CTF competition was held in February 2017, Web: explosion-2
How to apply the updated fluent 3.0 to applet development
What is a network port
asp. Net read TXT file
redis6主从复制及集群
What happened to the communication industry in the first half of this year?
49. Grouping of alphabetic ectopic words: give you a string array, please combine the alphabetic ectopic words together. You can return a list of results in any order. An alphabetic ectopic word is a
C object storage