This project is read-only.

Problem with PHPWord not adding text to a document

Aug 13, 2013 at 12:37 PM
Hi everybody,

I am currently working on a project that involves me creating a document through PHP, thus, PHPWord was the logical choice. However, I'm having a slight issue in that everything I am passing in to PHPWord is not being put into the document. When I open the document it is completely blank. My code is as follows:
require_once '../PHPWord.php';
        $PHPWord = new PHPWord();

        //Cover Sheet
        $coverSheet = $PHPWord->createSection();
        $coverSheet->addText(Input::get('cover_title'), array('name' => 'Tahoma', 'size' => 24));
        $coverSheet->addText(date('l dS F Y'), array('name' => 'Tahoma', 'size' => 18));

        $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
        $temp_filename = tempnam('', 'xyz');

        //Download the file and delete temp version
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename='.$temp_filename.'.docx');
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Content-Length: '.filesize($temp_filename));
Any ideas on how to fix this would be greatlyappreciated.