PHPWord icon indicating copy to clipboard operation
PHPWord copied to clipboard

Image wrappingStyle has no effect

Open donquick opened this issue 9 years ago • 10 comments

Hi whatever i put for the wrappingStyle variable in the image style array the image is inline when i open the doc in word. The array is being accessed because other element of the array are being used correctly, but the wrappingStyle is being ignored. After opening the doc, I can right click the image and change the format to 'behind text' or what i want, but I can't control it from the php. Any ideas. Also the marginTop and marginLEft are being ignored, just the width and height are working. Thanks:

$section->addImage('../CMS/images/greenblock.jpg',
        array('wrappingStyle' => 'behind', 'width' => 600, 'height' => 100, 'marginTop' => 3, 'marginLeft' => -1, 'align' => 'center')
    );

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

donquick avatar Mar 08 '15 20:03 donquick

I was having the same problem, but I noticed that if I told PHPWord to process \samples\Sample_13_Images.php, image wrapping was working fine in the resultant Word document. After a bit of experimentation I found that you must have 'positioning'=>'relative' in your settings array for the image wrapping to work correctly.

ComputerTinker avatar Jul 24 '15 21:07 ComputerTinker

Ahh! - well found - the moment has passed for me actually as i have been round the houses and back with this since then. I am now generating offline and uploading as there were other problems with my project. Hopefully your investigation will help others though. Cheers.

donquick avatar Jul 26 '15 11:07 donquick

I'm running into the same issue now. I have an image that covers the page and want text to be on top. Everything I try the image is always on top.

$section->addImage('resources/background.png', ['positioning' => 'relative', 'height' => 524, 'width' => 839, 'wrappingStyle' => 'behind']);

jmanring avatar Feb 02 '16 14:02 jmanring

So I found that in src/PhpWord/Writer/Word2007/Style/Frame.php if I change: $zIndices = array(FrameStyle::WRAP_INFRONT => PHP_INT_MAX, FrameStyle::WRAP_BEHIND => -PHP_INT_MAX); to $zIndices = array(FrameStyle::WRAP_INFRONT => 251658752, FrameStyle::WRAP_BEHIND => -251658752); it allows me to set the image to behind in word. What seems to be happening, in my case, is the PHP_INT_MAX equals 9223372036854775807 and my version of Word does not like an integer that large in the xml. By changing that number to the same setting that my Word uses it works.

jmanring avatar Feb 02 '16 15:02 jmanring

Wow, im so lucky that I found this issue. Very thanks @jmanring.

playmono avatar Apr 27 '16 23:04 playmono

Thanks Jmanring, after many tests the only thing that worked for me is your example, you saved my ass.

I discovered that the command that forces the text to be displayed in front of or behind the image is -> FBehindDocument - Boolean - Place the shape behind text. Example: {\ sp {\sn fBehindDocument} {\sv 1}}

Try to implement it inside the class-> PhpWord \ Writer \ Word2007 \ Element \ image.php

But I can not understand PHPWord, too much abstraction and inheritance, in theory that command should be incorporated into the function responsible for creating the style of shape.

Piece of a real document ...0001fffd9} }}{\sp{\sn posh}{\sv 1}}{\sp{\sn posrelh}{\sv 3}}{\sp{\sn posv}{\sv 1}}{\sp{\sn posrelv}{\sv 3}}{\sp{\sn fBehindDocument}{\sv 1}}{\sp{\sn fPseudoInline}{\sv 0}}{\sp{\sn fLayoutInCell}{\sv 1}}}{\shprslt\par\pard \ql \li0\ri0\widctlpar\posyt\dxfrtext180\dfrmtxtx180\dfrmtxty0\wraparound\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 {\pict\picscalex37\picscaley36\piccropl0\piccropr0\piccropt0\piccropb0 \picw47360\pich69189\picwgoal26850\pichgoal39225\wmetafile8\bliptag-2139107557\blipupi6{*\blipuid 807fcf1b05ac0faa3e79e72084be757a} 010009...

In the end after many hours I gave up and use your example, so again thank you very much

Bricobit avatar Jul 14 '17 13:07 Bricobit

Thanks @jmanring

bhavdip111 avatar Feb 17 '18 07:02 bhavdip111

Hi, I'm still having same issue on setImageValue.

There's my code: $templateProcessor->setImageValue('image_record', [ 'path' => $local_png, 'width' => 500, 'positioning' => 'reltive', 'wrappingStyle' => 'behind', ]);

But image still not going behind text. In PhpOffice\PhpWord\Writer\Word2007\Style the maxZIndex is 2147483647.

djandrew98 avatar Jul 29 '20 13:07 djandrew98

@djandrew98 try changing your code to: $templateProcessor->setImageValue('image_record', [ 'path' => $local_png, 'width' => 500, 'positioning' => 'relative', 'wrappingStyle' => 'behind', ]);

Maybe you found this one yourself already but you have relative spelled wrong in your code.

MAH313 avatar Aug 17 '20 13:08 MAH313

I was having the same problem, but I noticed that if I told PHPWord to process \samples\Sample_13_Images.php, image wrapping was working fine in the resultant Word document. After a bit of experimentation I found that you must have 'positioning'=>'relative' in your settings array for the image wrapping to work correctly.

Why is this still not in documentation?? https://phpword.readthedocs.io/en/latest/styles.html#image-style no positioning mentioned, but it works!!

alensimunic avatar Aug 17 '22 10:08 alensimunic

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue for you, please try to help by debugging it further and sharing your results. Thank you for your contributions.

github-actions[bot] avatar Nov 18 '22 02:11 github-actions[bot]