无法从rtf模板文件生成

时间:2020-02-06 09:27:43

标签: php php-zip-archive

我正在尝试将模板文件中存在的编码文本替换为其相应的文本,例如 性别为女性。之后,应下载新文件。下面的代码对于ms Word文档工作正常,但对于rtf文件则无效。

public function temp()
{   
    $name='Nida Amin';
    $class = 'M.C.A';
    $school = 'Kashmir University';
    $gender = 'Female';

    $source='Template.rtf';
    $destination='template_'.$name.'.rtf';
    $temp='template_'.$name.'.rtf';

    copy($source,$temp);

    $zip= new ZipArchive;

    $fileXml='word/document.xml';
    if($zip->open($temp) === TRUE)
    {
        $old=$zip->getFromName($fileXml);
        $new=str_replace("**Student Name**",$name,$old);
        $new=str_replace("**Class**",$class,$new);
        $new=str_replace("**Gender**",$gender,$new);
        $new=str_replace("**School**",$school,$new);

        $zip->deleteName($fileXml);
        $zip->addFromString($fileXml,$new);
        $zip->close();

        header("Content-Type: application/force-download");
        header('Content-Type: application/rtf');
        header('Content-Disposition: attachment; filename="'.$destination.'"');

       readfile($destination);
       unlink($destination);
       exit();
    }
}

我强烈认为此问题是由于$ fileXml ='word / document.xml';线。我无法在此行中找到rtf文件。基本上,我试图找到一种方法,可以在不修改文件中文本的原始格式(颜色,字体样式,图像)的情况下,从单个模板文件制作多个文件。任何帮助将不胜感激。

0 个答案:

没有答案
相关问题