希腊字母被替换为???一旦我使用 PHPWord 将 docx 转换为 pdf?

问题描述 投票:0回答:2

我做了以下简单的 laravel artisan 命令:

Artisan::command('test:pdf',function(){

    \PhpOffice\PhpWord\Settings::setPdfRendererName(\PhpOffice\PhpWord\Settings::PDF_RENDERER_DOMPDF);
    \PhpOffice\PhpWord\Settings::setPdfRendererPath('.');

    $tmpFile = storage_path().'/contracts/test.docx';
    $outfile = storage_path().'/contracts/test.pdf';

    $phpWord = \PhpOffice\PhpWord\IOFactory::load($tmpFile);
    $phpWord->save($outfile,'PDF');

});

它接收 docx 文件并将其转换为 pdf。但出于一个尴尬的原因,docx 包含希腊字母,一旦以 pdf 形式呈现,就会转换为

????

那么我有什么想法可以从 docx 保存 pdf 文件并尊重 UTF-8 字符吗?

php pdf dompdf laravel-5.7 phpword
2个回答
0
投票

这是由于 DOMPDF 的限制导致无法渲染希腊语字体。

您可以将所有字体替换为 DejaVu 字体或使用 mpdf。

Artisan::command('test:pdf',function(){

    \PhpOffice\PhpWord\Settings::setPdfRendererName(\PhpOffice\PhpWord\Settings::PDF_RENDERER_MPDF);
    \PhpOffice\PhpWord\Settings::setPdfRendererPath('.');

    $tmpFile = storage_path().'/contracts/test.docx';
    $outfile = storage_path().'/contracts/test.pdf';

    $phpWord = \PhpOffice\PhpWord\IOFactory::load($tmpFile);
    $phpWord->save($outfile,'PDF');

});


0
投票

在互联网上进行大量搜索后,我终于找到了波斯字母的正确解决方案,并将我的 .docx 文件转换为 pdf。

要将 Word 文件 (.docx) 转换为 Pdf,您必须按照以下步骤操作:

  1. 使用这个库
  2. 将word文件转换为html
  3. 使用 这个库
  4. 将 html 文件转换为 pdf

通过这种方法,我能够将word文件转换为pdf,波斯字母没有任何问题。🧐

© www.soinside.com 2019 - 2024. All rights reserved.