0

ユーザーフォームからアップロードされたサーバー側の画像を、LiveDocx を使用して生成された Word ドキュメントに追加しようとしています。

私のワードテンプレートはこんな感じです。

«image:photo»

別名

{ MERGEFIELD image:photo \* MERGEFORMAT }

私のphpは次のようになります。

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

画像があるはずの空白の領域が得られます。他の差し込み項目は正しく機能しています。

4

1 に答える 1

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»

別名

{ 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');
于 2012-11-13T19:05:22.830 に答える