I'm using the PHPWord plugin to convert HTML texts into a .docx file
But when I go to download the generated file, I get only with very crazy characters like:
PK ######## ^ uK j # c ###! ####### [Content_Types] .xml N 0 # E | E -J ܲ @ # 5 # * Q > 5' _ 8} = D # AC v #) s G G 5 "J J6, #, # ' nQ s ~ 2L ) a m # d | 5 m # F # K L) s r V # 8 T > Z 5.x # C,
I have already looked here in stackoverflow, in the project's own github and google in general, but I could not solve the problem.
My code goes below:
<?php
error_reporting (E_ALL | E_STRICT);
@ini_set ('display_errors', 'on');
require_once '../../../../vendor/autoload.php';
$my_content = $_POST['html_content'];
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
\PhpOffice\PhpWord\Shared\Html::addHtml($section, $my_content);
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachement;filename="teste.docx"');
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('php://output');
?>