I would like to load an ODF file as a template, do a variable (string) replacement on the document, and output a new ODF file with the replaced strings. Is this possible with phpdocx or should I be looking for another tool?
Here's what I currently have:
$docx = new CreateDocx();
$docx->setTemplateSymbol('^');
$docx->enableCompatibilityMode();
$docx->addTemplate($source);
$docVarArray = $docx->getTemplateVariables();
// TODO phpdocx variable replacement here.
$docx->createDocx($destination);
...which dies during $docx->addTemplate($source)
with the error:
PHP message: PHP Fatal error: Call to a member function appendChild() on a non-object in /path/libs/phpdocx/classes/CreateTemplate.inc on line 433
PHP message: PHP Stack trace:
PHP message: PHP 1. {main}() /path/script.php:0
PHP message: PHP 2. CreateDocx->addTemplate() /path/script.php:40
PHP message: PHP 3. CreateTemplate->openTemplate() /path/libs/phpdocx/classes/CreateDocx.inc:4119
PHP message: PHP 4. CreateTemplate::addRelationship() /path/libs/phpdocx/classes/CreateTemplate.inc:711" while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "POST /script.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php
I believe this is failing because phpdocx is expecting a MSWord document.
Thanks!
Sorry but this is not possible, your template need to be a docx file.