PHPOffice / PHPWord

A pure PHP library for reading and writing word processing documents
https://phpoffice.github.io/PHPWord/
Other
7.26k stars 2.69k forks source link

Image wrappingStyle has no effect #489

Open donquick opened 9 years ago

donquick commented 9 years ago

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!](https://www.bountysource.com/issues/9332080-image-wrappingstyle-has-no-effect?utm_campaign=plugin&utm_content=tracker%2F323108&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F323108&utm_medium=issues&utm_source=github).
ComputerTinker commented 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.

donquick commented 9 years ago

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.

jmanring commented 8 years ago

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 commented 8 years ago

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.

playmono commented 8 years ago

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

Bricobit commented 7 years ago

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

bhavdip111 commented 6 years ago

Thanks @jmanring

djandrew98 commented 4 years ago

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.

MAH313 commented 4 years ago

@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.

alensimunic commented 2 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.

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

github-actions[bot] commented 1 year ago

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.