当前位置:网站首页>Laravel dompdf exports PDF, and the problem of Chinese garbled code is solved
Laravel dompdf exports PDF, and the problem of Chinese garbled code is solved
2022-07-05 13:53:00 【Kun of the deep sea】
composer install dompdf package
composer require barryvdh/laravel-dompdf
Publish profile , Generated profile config/dompdf.php, You can also choose to ignore this step
php artisan vendor:publish --provider="Barryvdh\DomPDF\ServiceProvider"
Use here Facade export , Click to see more
use PDF;
$pdf = PDF::loadView('pdf.invoice', $data);
return $pdf->download('invoice.pdf');
dompdf There's No... in the bag unicode Chinese coded font , Garbled when exporting Chinese . Need to install custom Chinese fonts . I chose msyh.ttf Microsoft YaHei Font , After the font is rendered , Derived pdf The file will be slightly larger , You can choose other fonts by yourself .
download php_font.php Script , Extraction requires dompdf Required font ,php_font Tool scripts
- First, we'll download the good one msyh.ttf Download fonts to local , Paste into the following two directories , One is laravel Project root , Two is public Under the table of contents .php_font.php The file is also copied to the project root directory .
Insert picture description here - Execute command extraction msyh Font to dompdf in , Here are the success stories
- We need to pay attention to storage Is there any fonts Catalog , If there is no local to create , Render here pdf when , A font cache file will be generated .( You may need to give storage/fonts/* Grant authority )
- stay blade The specific usage in the document is as follows :
@font-face {
font-family: 'msyh';
font-style: normal;
font-weight: normal;
src: url(./msyh.TTF) format('truetype');
}
body {
font-family: 'msyh';
}
Attention is also needed ,blade file meta The label must be utf-8 code
The operation is complete , Can export pdf 了 .
边栏推荐
- PHP basic syntax
- Zibll theme external chain redirection go page beautification tutorial
- Attack and defense world crypto WP
- Intranet penetration tool NetApp
- 【云资源】云资源安全管理用什么软件好?为什么?
- stm32逆向入门
- Ueditor + PHP enables Alibaba cloud OSS upload
- :: ffff:192.168.31.101 what address is it?
- ::ffff:192.168.31.101 是一个什么地址?
- aspx 简单的用户登录
猜你喜欢
Win10 - lightweight gadget
Aikesheng sqle audit tool successfully completed the evaluation of "SQL quality management platform grading ability" of the Academy of communications and communications
RK3566添加LED
[server data recovery] a case of RAID5 data recovery stored in a brand of server
Zibll theme external chain redirection go page beautification tutorial
Ordering system based on wechat applet
jasypt配置文件加密|快速入门|实战
【公开课预告】:视频质量评价基础与实践
Operational research 68 | the latest impact factors in 2022 were officially released. Changes in journals in the field of rapid care
Deep copy is hard
随机推荐
鏈錶(簡單)
Jetpack Compose入门到精通
2022司钻(钻井)考试题库及模拟考试
Rk3566 add LED
Solve the problem of "unable to open source file" xx.h "in the custom header file on vs from the source
深拷贝真难
Require, require in PHP_ once、include、include_ Detailed explanation of the efficiency of repeated introduction of once class library
Anchor navigation demo
Convolutional Neural Networks简述
NFT value and white paper acquisition
:: ffff:192.168.31.101 what address is it?
Request + BS4 crawl Netease cloud music popular comments
Programmer growth Chapter 8: do a good job of testing
Requset + BS4 crawling shell listings
网络安全-HSRP协议
Summit review | baowanda - an integrated data security protection system driven by compliance and security
真正的缓存之王,Google Guava 只是弟弟
Deep copy is hard
【云资源】云资源安全管理用什么软件好?为什么?
Controller in laravel framework