I have searched all available documentation for a possibility to create some header (paragraph) which has a border and a background color. Finally, it was here on github that someone pointed out that the borderSize and borderColor attributes are available on the addText method. Please note that these styles are not yet documented on readthedocs.org. However, I also tried adding a background color using bgColor, but that did not work. I wonder how it is possible to create a title or paragraph, full width, having a border and a background color. The closest I got was setting a background color for the text. See my example below. I want the whole box having that background color, without any white gaps and I'm sure there is some way to achieve this. However, I did not find anything about this in the docs. Maybe you guys can help out here?
Code:
$titlepage->addText("My Title", array("size" => 24, "color" => "FF0000", "bgColor"=>"00FF00"), array("bgColor"=>"00FF00", "borderSize"=>6, "borderColor"=>"0000FF"));
Output:
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
I just found out by looking at the source code: if you want to set the paragraph background color you will have to set the shading of the paragraph style:
$section->addText('Your text', array(), array('shading' => array('fill' => 'dddddd')));
The background color for the paragraph style is set as the fill of the shading.
As far I can tell, you have to read the PhpWord API
http://phpoffice.github.io/PHPWord/docs/master/classes/PhpOffice.PhpWord.Style.Shading.html
and / or the docx specification
http://officeopenxml.com/WPshading.php
to find the right parameters for the "shading".
Most helpful comment
I just found out by looking at the source code: if you want to set the paragraph background color you will have to set the shading of the paragraph style:
The background color for the paragraph style is set as the fill of the shading.
As far I can tell, you have to read the PhpWord API
http://phpoffice.github.io/PHPWord/docs/master/classes/PhpOffice.PhpWord.Style.Shading.html
and / or the docx specification
http://officeopenxml.com/WPshading.php
to find the right parameters for the "shading".