使用livedocx和php合并不在Word 2007中显示的图像的字段

时间:2012-11-13 19:05:23

标签: php word-2007 livedocx

我正在尝试将从用户表单上传的服务器端图像添加到使用LiveDocx生成的Word文档中。

我的单词模板看起来像这样。

«image:photo»

AKA

{ MERGEFIELD image:photo \* MERGEFORMAT }

我的php看起来像这样。

$mailMerge = new Zend_Service_LiveDocx_MailMerge();
$mailMerge->uploadImage($this->logo_path);
$mailMerge->assign('image:photo', $this->logo_path);

我只得到一个空白区域,图像应该是。我的其他合并字段正常工作。

1 个答案:

答案 0 :(得分:2)

我没有意识到LiveDocx只存储要引用的文件的名称。我发现了这个:

$mailMerge->listImages();

这种格式是这样的:

array
0 => array
  'filename' => string 'directory_logo.png' (length=18)
  'fileSize' => int 12829
  'createTime' => int 1352835686
  'modifyTime' => int 1352835686

所以这个格式的模板文件很好:

«image:photo»

AKA

{ MERGEFIELD image:photo \* MERGEFORMAT }

但我的php需要看起来像这样:

$mailMerge->uploadImage($this->logo_path);
$mailMerge->assign('image:photo', $this->logo_file);

我的完整工作代码如下所示:

$mailMerge = new Zend_Service_LiveDocx_MailMerge();
$mailMerge->setUsername($username)
  ->setPassword($password);
$mailMerge->setLocalTemplate($template_path . '/service_template.docx');
$mailMerge->uploadImage($this->logo_path);
$mailMerge->assign('image:photo', 'directory_logo.png');
$mailMerge->createDocument();
$document = $mailMerge->retrieveDocument('docx');
file_put_contents($this->config->livedocx->document . '/' . $this->prefs['serverid'] . '/service_directory.docx', $document);
$mailMerge->deleteImage('directory_logo.png');