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 协议》,转载必须注明作者和本文链接
写代码是一件趣事。
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 7

centos 没有这个字体文件吧 SimSun

/var/share/fonts

1年前 评论

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

1年前 评论
adong (楼主) 1年前

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

1年前 评论

/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

1年前 评论
adong (作者) (楼主) 1年前