Hi,
(I have an advanced licence)
I have issues using our own file as base for the generated Word files (we do not need to replace anything withing the Word file itself, we just convert our HTML to a Word document, hence we just want to use the styling from that template file).
Here is the code used to create the file
$wordTemplate = 'docx';
$customTemplatePath = storage_path("app/system/templates/word-templates/{$context->getStylesheetName()}.docx");
if (file_exists($customTemplatePath))
{
$wordTemplate = $customTemplatePath;
}
$docx = new CreateDocx($wordTemplate);
$docx->embedHTML($htmlContent, [
'useHTMLExtended' => true,
'isFile' => false,
'strictWordStyles' => false,
'wordStyles' => [
'h1' => 'Titre 1',
'h2' => 'Titre 2',
'h3' => 'Titre 3',
],
]);
$docx->createDocx($wordFile);
When not using a custom template, no problem, the file is generated.
When using a custom template (empty basic Word file created with Office 2019), we get a warning:
ErrorException {#7987
#message: "dom_import_simplexml() expects parameter 1 to be object, bool given"
#code: 0
#file: "./packages/phpdocx/Classes/Phpdocx/Utilities/DOCXStructure.php"
#line: 166
#severity: E_WARNING
trace: {
./packages/phpdocx/Classes/Phpdocx/Utilities/DOCXStructure.php:166 {
Illuminate\Foundation\Bootstrap\HandleExceptions->handleError($level, $message, $file = '', $line = 0, $context = [])
› // get the main document XML and rename it to word/document.xml
› $contentTypesDom = dom_import_simplexml($contentTypesXml);
› $contentTypesXpath = new \DOMXPath($contentTypesDom->ownerDocument);
}
Illuminate\Foundation\Bootstrap\HandleExceptions->handleError() {}
./packages/phpdocx/Classes/Phpdocx/Utilities/DOCXStructure.php:166 { …}
./packages/phpdocx/Classes/Phpdocx/Create/CreateDocx.php:790 { …}
I have tried to mute that warning (@new), but that did not help.
I tried using CreateDocxFromTemplate but that did not help either.