Reputation: 31
phpword wrong exports base64 images to docx file.
i have html with base64 images. i want to export this html to docx file. i use phpword.
$html = $obText->getHtml();
$pw = new \PhpOffice\PhpWord\PhpWord();
$section = $pw->addSection();
\PhpOffice\PhpWord\Shared\Html::addHtml($section, $html, false, false);
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($pw, 'Word2007');
$objWriter->save($finalFilePath);
afther that - i have docx file with texts, tables, but without images. why? whats wrong?
Upvotes: 1
Views: 1746
Reputation: 31
I found solution. In my case problem was, that html's tag img was invalid. Reason was - that CRM , where i store data added special symbols of new line to base64 image data.
so i just made $html = str_replace("%0D%0A", "", $html);
Upvotes: 1
Reputation: 1029
in source PHPOffice
'img' => array('Image', .....
preg_match('/data:image\/(\w+);base64,(.+)/', $src, $match);
template must be similar
<img src="data:image/gif;base64,--base64-coded-data---">
Upvotes: 1