Forum


Replies: 3   Views: 3778
Phpdocx error while trying to open a template
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by legalvorce  · 03-08-2017 - 15:37

I have downloaded phpdocx and I am testing my code on my local environment. I can successfully create a document from scratch with the following code:

$docx = new \Phpdocx\Create\CreateDocx();

$docx->addText('This is a test');
$docx->embedHTML('<p style="font-size: 30px;">New paragraph</p>');
$docx->createDocx(public_path() . '/output.docx');

However, I am needing to create a document from a template. Everytime I do so though I get the following error message: Error while trying to open the (base) template as a zip file

Here is my code:

$docx = new \Phpdocx\Create\CreateDocxFromTemplate(public_path() . '/Example Template.docx');

$variables = [
    '1' => 'John',
    '2' => 'Allen',
];

$docx->replaceVariableByText($variables);
$docx->createDocx(public_path() . '/output.docx');

Also, I am attaching a screenshot with more error details below:

https://i.stack.imgur.com/0jCEp.png