使用PHPword创建pdf到docx文件

时间:2016-03-25 12:08:39

标签: php pdf xmlwriter phpword

我用来创建一个.docx文件的PHP单词,我有一个pdf文件。创建.docx文件但是当我试图在window machine中打开这个文件时它没有打开。在Linux机器上它正确显示。我尝试了很多东西。

那是我的代码: -

      spl_autoload_unregister(array('YiiBase','autoload'));
      Yii::import('application.extensions.PHPWord.PHPWord',true);
      require_once('PHPWord/PHPWord.php');
      $PHPWord = new PHPWord();
      spl_autoload_register(array('YiiBase','autoload'));
      $document = $PHPWord->loadTemplate("/var/www/frontsite/agemodern/uploads/roadmaps/".$file);
      $document->setValue('Value1', 'Sun');
      $newfile='ageModern Roadmap - '.date('m-d-Y',time()).' - '.time().'.docx';

     $document = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');

     $document->save("/var/www/frontsite/agemodern/uploads/roadmaps/".$newfile);

这是我的phpword文件代码: -

    $zip_name=$strFilename;
    if(file_exists($zip_name))
    {

    $filename=$zip_name;

    //header("Content-Type: application/force-download");
    header('Content-Type: application/octet-stream');
    //header("Content-Type: application/download");
    header("Content-Disposition: attachment; filename=\"{$zip_name}\"");
    header('Content-Disposition: attachment; filename="'.$zip_name.'"');
    header("Content-Transfer-Encoding: binary ");  
    readfile($filename);


    //readfile($zip_name);
    // remove zip file is exists in temp path
    unlink($filename);
    }

提前谢谢

0 个答案:

没有答案
相关问题