Hello!
I am currently trying out the trial version to check if phpdocx meets my requirements.
I'm trying to add a header and footer to my document, but to no avail. I tried copying the demo header (example 2, the text part), but I couldn't get the script to output anything.
Of course, with the obfuscated files, PhpStorm does not recognize any functions from the WordFragment class, so it might just be that I'm mising something.
Here is my current code:
public function print($fileType = 'docx')
{
$json = file_get_contents('php://input');
$data = json_decode($json,true)['data'];
$docx = new CreateDocx();
ob_start();
$textOptions = array(
'fontSize' => 13,
'b' => 'on',
'color' => '567899',
);
$headerText = new WordFragment($docx, 'defaultHeader');
$headerText->addText('PHPDocX Header Title', $textOptions);
$docx->addHeader(array('default' => $headerText));
$docx->embedHTML($data['html']);
ob_end_clean();
$docx->createDocx($data['filename']);
if($fileType === 'pdf') {
$docx->transformDocument($data['filename'] . '.docx', $data['filename'] . '.pdf');
}
header("Content-Type: application/msword");
header("Content-Disposition: attachment; filename=" . $data['filename'] . "." . $fileType);
header("Content-Length: " . filesize($data['filename'] . '.' . $fileType));
header("Content-Transfer-Encoding: binary");
readfile($data['filename'] . '.' . $fileType);
ob_end_flush();
return new Response();
}
PS: I am aware that I currently do not delete the generated file. I was planning to implement that after I got everything working.