Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPWord horizontal line (<hr />)

Tags:

php

phpword

I am currently using PHPWord to generate my documents, but I want to add an horizontal line in the document. Just like an


in HMTL. In word you can do this by typing three underscores en enter, but I want to use it in my generated document.

Does anybody have more information about this feature?

Thank you!

like image 967
HansElsen Avatar asked Dec 20 '22 21:12

HansElsen


2 Answers

I decompressed the '.docx' file, found closest xml tag is 'w:pBdr'.

<w:pBdr><w:bottom w:val="single" w:sz="6" w:space="0" w:color="auto"/></w:pBdr>

So, I insert a horizontal line by ParagraphStyle.

$section->addText('', [], ['borderBottomSize' => 6]);
like image 182
Dragon Avatar answered Jan 03 '23 02:01

Dragon


It's also possible to add a horizontal line to a section, instead of adding a border:

$section->addLine(['weight' => 1, 'width' => 600, 'height' => 0]);

Note that the width is in pixels, which is the main disadvantage of this method. You need to know what the width of your page (minus the margins) is in pixels. If you set it to some large number then the line will just continue through to the right side of your page, ignoring the margin.

like image 32
bjrn Avatar answered Jan 03 '23 00:01

bjrn