Problem with PHPWord not adding text to a document

Aug 13, 2013 at 11:37 AM
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->addTextBreak(1);
        $coverSheet->addText(date('l dS F Y'), array('name' => 'Tahoma', 'size' => 18));
        $coverSheet->addTextBreak(1);
        $coverSheet->addImage(Input::get('company_logo'));
        $coverSheet->addImage(Input::get('client_logo'));

        //Saving
        $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
        $temp_filename = tempnam('', 'xyz');
        $objWriter->save($temp_filename.'.docx');


        //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));
        flush();
        readfile($temp_filename);
        unlink($temp_filename);
        exit;
Any ideas on how to fix this would be greatlyappreciated.