Forum


Replies: 1   Views: 1986
Html styling for div, hr and borders around p
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by admin  · 06-07-2020 - 18:23

Hello,

paragraphs in MS Word don't work in the same way than HTML. We recommend you to open MS Word and generate a new paragraph with the output you'd like to get, as you can check, you can't apply a padding to a paragraph unless you add a border, this border allows to set custom internal paddings. The current version of HTML to DOCX doesn't allow applying a spacing value when adding a paragraph border, so you'd need to use a custom paragraph style:

$style = array(
    'backgroundColor' => '#999999',
    'border' => 'single',
    'borderColor' => '#999999',
    'borderWidth' => 1,
    'border_top_space' => 20,
    'border_bottom_space' => 20,
    'textAlign' => 'center',
);
$docx->createParagraphStyle('myParagraphStyle', $style);

$html = '
    <p class="myParagraphStyle">My paragraph</p>
';
$docx->embedHTML($html, array('wordStyles' => array('.myParagraphStyle' => 'myParagraphStyle'), 'strictWordStyles' => true));

paddings and margins applied to paragraph are added to phpdocx in the same way than MS Word and both values increment the margins from other contents/margins.

As alternative, and maybe easiest approaches, you could use a table with a single cell or add a textbox.

Regards.