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 协议》,转载必须注明作者和本文链接
写代码是一件趣事。
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 7

centos 没有这个字体文件吧 SimSun

/var/share/fonts

7个月前 评论

字体文件拷贝到/usr/share/fonts目录,然后执行fc-cache -f -v

7个月前 评论
adong (楼主) 7个月前

生成PDF方块的字体 一直是 DejaVuSerifCondensed

7个月前 评论

/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,

file

7个月前 评论
adong (作者) (楼主) 7个月前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!