douchi2022 2012-11-13 19:05
浏览 14
已采纳

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

I'm trying to add a server side image uploaded from a user form to a Word document that gets generated using LiveDocx.

My word template looks like this.

«image:photo»

AKA

{ MERGEFIELD image:photo \* MERGEFORMAT }

My php looks like this.

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

I just get a blank area where the image should be. My other merge fields are working properly.

  • 写回答

1条回答 默认 最新

  • dongtun2572 2012-11-13 19:05
    关注

    I didn't realize that LiveDocx stores only the name of the file to be referenced. I found this out using:

    $mailMerge->listImages();
    

    The format came back like this:

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

    So the template file was fine with this format:

    «image:photo»
    

    AKA

    { MERGEFIELD image:photo \* MERGEFORMAT }
    

    But my php needed to look like this:

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

    My full working code looks like this:

    $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');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案