centos7 excel,图片等转PDF问题
已解决!
- 服务器环境 :
centos7
laravel7
php7.4
Nginx
centos7本系统带python2.7,我单独安装了一个python3.6
- 2个问题都是中文转码:
1.laravel7里面执行 exe(“python3 /www/wwwroot/mqtt/app/test.py “中文路径”) 就会显示变错误,但是我直接使用python3 执行就可以带中文路径参数。
2.laravel7 使用use PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf;
下面是代码片段
/*
Mpdf 8.2
phpoffice/phpspreadsheet: "^1.18",
*/
$pdfWriter = new Mpdf($spreadsheet);
$pdfWriter->setFont('SimSun', '', 12); // 设置字体为SimSun(中文字体)
$pdfWriter->save($pdfOutputFilePath);
把excel转PDF,结果中文都是方块。
我设置字体SimSun ,结果输出的PDF方块的字体还是 DejaVuSerifCondensed。没思路了,求解救!
本作品采用《CC 协议》,转载必须注明作者和本文链接
安装字体
centos 没有这个字体文件吧 SimSun
/var/share/fonts
字体文件拷贝到/usr/share/fonts目录,然后执行fc-cache -f -v
生成PDF方块的字体 一直是 DejaVuSerifCondensed
/vendor/mpdf/mpdf/src/Config/ConfigVariables.php
// AUTOMATIC FONT SELECTION // Based on script and/or language // mPDF 6.0 (similar to previously using function SetAutoFont() ) 直接在这里面改 false 为true就好了。
'autoScriptToLang' => true,
'autoLangToFont' => true,