phpdocx add image makes docx corrupt

馋奶兔 提交于 2019-12-11 11:10:35

问题


It has been asked before, years ago, but with no answer corrupt docx when adding image

Hey

I have a template where i replace some variables and generate a docx document... That works fine..

As soon as i add an image, word tells me that the files is corrupt. But letting Word correct the error gives me the document as i expect it to be with the image.

Im adding image like this...

$docx->addBreak(array('type' => 'page'));
            $options = array(
            'src' => $value['110333870356bc784cf1b6b0.56722572.png'],
            'imageAlign' => 'center',
            'scaling' => 100,
            'spacingTop' => 10,
            'spacingBottom' => 0,
            'spacingLeft' => 0,
            'spacingRight' => 20,
            'textWrap' => 0,

            );
            $docx->addImage($options); 

Im lost here .. ? ..


回答1:


After being in contact with 2mdc (Creator of phpDocX) they told me, that PHP is not able to get the right extension because of the filename of the image i am inserting. As a result phpDocX adds some wrong values (such as dpi and image extension name).

As mentioned in my question, Word is able to detect those errors and correct them.

Changed my routine which creates my "unique" image names, to make sure that dot's are not present and it fixed the problem ..

As a result, filename: 110333870356bc784cf1b6b0.56722572.png will instead become 110333870356bc784cf1b6b0656722572.png (or other generated filename).




回答2:


Just to share my experience. I had exactly the same problem but not for the same reason. It was because the image file extension I wanted to insert (addImage) was in capital letter. Example :

  • image.JPG ==> result a "corrupt" file.
  • image.jpg ==> result OK !

I hope it will help someone...



来源:https://stackoverflow.com/questions/35372094/phpdocx-add-image-makes-docx-corrupt

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