Search code examples
phptemplateszend-frameworkdocxlivedocx

Zend LiveDocx - Cannot read local template from disk


I am trying to create a word document in my zend framework project but it isn't working!

This is my action code:

public function createwordAction(){
    $this->_helper->layout->disableLayout();
    $this->_helper->viewRenderer->setNoRender();

    require_once 'Zend/Service/LiveDocx/MailMerge.php';

    try{
        $mailMerge = new Zend_Service_LiveDocx_MailMerge();

        $mailMerge->setUsername('***********')
                  ->setPassword('******');

        $mailMerge->setLocalTemplate('/license-agreement-template.docx');

        $mailMerge->assign('software', 'Magic Graphical Compression Suite v1.9')
            ->assign('licensee', 'Henry Döner-Meyer')
            ->assign('company',  'Co-Operation')
            ->assign('date',     'January 11, 2010')
            ->assign('time',     'January 11, 2010')
            ->assign('city',     'Berlin')
            ->assign('country',  'Germany');

        $mailMerge->createDocument();

        $document = $mailMerge->retrieveDocument('pdf');

        file_put_contents('document.pdf', $document);
    }
    catch (Exception $e) {
        die ('Application error: ' . $e->getMessage());
    }
}

My template is located in the root of my project (public folder). The template is downloaded from this tutorial and I haven't edited or opened it ... .

The catch exception shows this error:

Application error: Cannot read local template from disk.

I also tried changing my path to the template to this:

$templatepath = APPLICATION_PATH + "../public/license-agreement-template.docx";
$mailMerge->setLocalTemplate($templatepath);

But same result ...

Then I tried to change the file permissions with chmod like this:

chmod("/license-agreement-template.docx",0755);

And then I got this error:

Warning: chmod(): No such file or directory

Does anyone has experienced the same problem? Or can somebody help me with this?


Solution

  • I never heard of LiveDocx, but here is what I have done:

    • Searched the source of LiveDocx for your particular error:

    And here it is

    The exception is thrown if (!is_readable($filename))

    There's probably some right issues with your file (or your file name is incorrect) Change permissions of file uploaded by PHP