Answer the question
In order to leave comments, you need to log in
How to set encoding in PHPWord + DOMPDF?
Hello. I'm trying to convert docx to pdf using the PHPWord + DOMPDF bundle, but the Cyrillic alphabet is displayed as question marks. Please tell me how to fix this.
My code:
$rendererName = Settings::PDF_RENDERER_DOMPDF;
$rendererLibraryPath = Yii::getAlias('@app/vendor/dompdf/dompdf');
Settings::setPdfRenderer($rendererName, $rendererLibraryPath);
$reader = IOFactory::createReader('Word2007');
$doc = $reader->load($filepath);
$writer = IOFactory::createWriter($doc, 'PDF');
$writer->save($convpath);
Answer the question
In order to leave comments, you need to log in
You make two requests to Google:
"dompdf encoding" - and on the very first page you get information that DOMPDF works fine with Unicode.
"PHPWord utf-8" - and it turns out that this one works with Unicode through the ass, and there are crutches for necrophiles like this: https://phpstack.ru/php/kirillitsa-v-phpword.html
The problem may be not so much in phpword, but in rendering (dompdf, TCPDF). Using dompdf as an example, a possible solution is: use a DejaVu family font
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$phpWord->setDefaultFontName('dejavu sans');
\PhpOffice\PhpWord\Settings::setPdfRendererPath('./dompdf');
\PhpOffice\PhpWord\Settings::setPdfRendererName('DomPDF');
Help the seeker
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question