Hello,
phpdocx can change DOTM files as DOCX files replacing and adding contents. Please note that DOCM must be saved with the docm extension. For example:
$docx = new CreateDocxFromTemplate('sample_template_docm.docm');
$first = 'New content';
$variables = array('VAR' => 'New content');
$docx->replaceVariableByText($variables);
$docx->addText('A new paragraph.');
$docx->createDocx('output.docm');
These files can be transformed to PDF using the conversion plugin. Due to security reasons, macros embedded in them won't run automatically. Please note that LibreOffice macros are not the same as MS Word macros. You may need to change the default settings of these programs to run macros.
Regards.