Open donquick opened 9 years ago
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.
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.
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']);
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.
Wow, im so lucky that I found this issue. Very thanks @jmanring.
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
Thanks @jmanring
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 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.
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!!
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.
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: