three3
three3

Reputation: 2846

phpdocx Error while trying to open a template

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:

enter image description here

Upvotes: 2

Views: 1074

Answers (0)

Related Questions