当前位置:网站首页>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 了 .
边栏推荐
- Could not set property 'ID' of 'class xx' with value 'XX' argument type mismatch solution
- Self built shooting range 2022
- Jasypt configuration file encryption | quick start | actual combat
- Intranet penetration tool NetApp
- 这18个网站能让你的页面背景炫酷起来
- UE源码阅读[1]---由问题入手UE中的延迟渲染
- Apicloud studio3 WiFi real machine synchronization and WiFi real machine preview instructions
- Primary code audit [no dolls (modification)] assessment
- 深拷贝真难
- The real king of caching, Google guava is just a brother
猜你喜欢
Summit review | baowanda - an integrated data security protection system driven by compliance and security
In addition to the root directory, other routes of laravel + xampp are 404 solutions
jasypt配置文件加密|快速入门|实战
redis6事务和锁机制
Zibll theme external chain redirection go page beautification tutorial
PHP basic syntax
Internal JSON-RPC error. {"code":-32000, "message": "execution reverted"} solve the error
Usage, installation and use of TortoiseSVN
Laravel framework operation error: no application encryption key has been specified
Kotlin协程利用CoroutineContext实现网络请求失败后重试逻辑
随机推荐
Convolutional Neural Networks简述
Programmer growth Chapter 8: do a good job of testing
Can graduate students not learn English? As long as the score of postgraduate entrance examination English or CET-6 is high!
这18个网站能让你的页面背景炫酷起来
嵌入式软件架构设计-消息交互
Jetpack compose introduction to mastery
Require, require in PHP_ once、include、include_ Detailed explanation of the efficiency of repeated introduction of once class library
如何把大的‘tar‘存档文件分割成特定大小的多个文件
4年工作经验,多线程间的5种通信方式都说不出来,你敢信?
Win10 - lightweight gadget
Etcd database source code analysis -- rawnode simple package
[machine learning notes] how to solve over fitting and under fitting
Redis6 data type and operation summary
牛客网:拦截导弹
Internal JSON-RPC error. {"code":-32000, "message": "execution reverted"} solve the error
Zhubo Huangyu: these spot gold investment skills are not really bad
uplad_ Labs first three levels
Zibll theme external chain redirection go page beautification tutorial
Record in-depth learning - some bug handling
Liar report query collection network PHP source code