Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paragraph Settings for Image, Table #1437

Open
1 task done
BBalazsJurgen opened this issue Jul 18, 2018 · 5 comments
Open
1 task done

Paragraph Settings for Image, Table #1437

BBalazsJurgen opened this issue Jul 18, 2018 · 5 comments

Comments

@BBalazsJurgen
Copy link

BBalazsJurgen commented Jul 18, 2018

While it might happen that we have overlooked something, I am quite certain that this might be a missing feature. If not, please point us in the right direction.

This is:

  • a feature request?

Current Behavior

You can't set paragraph options for images and tables - that is, you can't define spaceBefore, spaceAfter or keepNext for Images and Tables, as you can see in the reference:
http:https://phpword.readthedocs.io/en/latest/styles.html
Spacing and keepNext are only available for paragraphs.

How to Reproduce

Now the thing is, if you add an image using the following code:
$section->addImage(dirname(dirname(__FILE__))."/uploads/123.png", array( "spaceBefore"=>0, "spaceAfter"=>0, "width" => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(12) ));
the spaceBefore, spaceAfter and keepNext (not present in the example) settings are ignored. However, it really is a frequent desire to be able to:

  • control the spacing after an image
  • keep the next line, often a subtitle with the image, together with the image itself.

Expected Behavior

Now, in MS Word, you can set these paragraph options simply by clicking the image and going to paragraph settings. How can you resolve this issue without having to resort to defining keepNext in setDefaultParagraphStyle, which is much too counterintuitive. I'm open to any suggestions you have to offer. Thanks!

Context

  • PHP version: 5.6
  • PHPWord version: 0.13.0

Edit: Edited to better match the formatting requirements.

@steal9pro
Copy link

Need that feature too. Thanks for issue!

@lijkbezorger
Copy link

It would be great if it will be implemented!

@steal9pro
Copy link

@BBalazsJurgen trick solution

$wrapperTable = $section->addTable(); 
$row = $wrapperTable->addRow(null, ['cantSplit' => true]);
$cell = $row->addCell();
$table = $cell->addTable($this->tableStyle);

Just wrap table or image you need into other "wrapper" table and that's it.

@LogansUA
Copy link

Same for me, still waiting for this

@xraphael75
Copy link

xraphael75 commented Jul 11, 2019

As Myrkotyn suggested, I was able to wrap the image in a textrun and then set the paragraph styling on the textrun.

	$textrun = $section->addTextRun(array('spaceAfter' => 0));
	$img = $textrun->addImage(
		$_SERVER['DOCUMENT_ROOT'] . '/images/email_signatures/logo.jpg',
		array(
			'width'         => 37.5, 
			'height'        => 21, 
			'marginTop'     => 0,
			'marginLeft'    => 0,
			'wrappingStyle' => 'square',
		)
	);

While this works, it would be nice if:

  • the documentation explained this
  • the addimage function supported paragraph styles directly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants