PHPWord: Replaced image doesn't gets actually replaced

我的梦境 提交于 2019-12-23 23:29:26

问题


I have a word document (template) which contains some images that I have to replace with others that are present on the drive. The images that exist in the documents are currently blank. And the ones that will replace them have some text written on them. One way to do was to edit each document and then by double-clicking the image I use the Pbrush to edit the image. Other way is below.

I used PHPWord to do the job. Open the document and replace the image in the word/media.

The problem: At first look it looks like the image has been replaced. Also, if I check through zip/winrar the images are replaced. But when I double click the image in the doc I see the old(blank) image in PBrush. I want the new edited image to show up. Or an alternate way to do the job.

This function does not exist in the original PHPWord but found it as the quick fix to do the job. (PhpWord/Template.php)

public function replaceImage($path,$imageName) {
    $this->_objZip->deleteName('word/media/'.$imageName);
    $this->_objZip->addFile($path,'word/media/'.$imageName);
}

My Code:

$PHPWord = new PHPWord();
$document = $PHPWord[$i]->loadTemplate('ALL_FILES/Template.docx');
$document->replaceImage($oldImage, $newImage);
$document->save('ALL_FILES/genForms/updatedDoc.docx');

P.S. Hope it is clear what I am trying to say. If need be, I can upload a test document somewhere, in case the problem is not clear.

来源:https://stackoverflow.com/questions/23425515/phpword-replaced-image-doesnt-gets-actually-replaced

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!