Reputation: 1753
I am currently using PHPWord to generate my documents, but I want to add an horizontal line in the document. Just like an
Does anybody have more information about this feature?
Thank you!
Upvotes: 4
Views: 14652
Reputation: 105
You can add lines using the addLine method.
Quoted from : https://phpword.readthedocs.io/en/latest/elements.html?highlight=line#line
$lineStyle = array('weight' => 1, 'width' => 100, 'height' => 0, 'color' => '38c172');
$section->addLine($lineStyle);
Available line style attributes:
Upvotes: 1
Reputation: 189
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]);
Upvotes: 8
Reputation: 919
I think closest to the <hr>
is the border attribute on a paragraph:
$phpWord->addParagraphStyle('myBorderStyle', array(
'borderSize' => \PhpOffice\PhpWord\Shared\Converter::pointToTwip(1),
'borderColor' => 'FF0000',
'borderBottomSize' => \PhpOffice\PhpWord\Shared\Converter::pointToTwip(4),
'borderTopColor' => '00FF00'
));
Notable:
top
, right
, bottom
, left
) individually.dashed
).Upvotes: 1
Reputation: 126
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.
Upvotes: 4
Reputation: 22741
Can you try using to add table and applying border instead of to add <hr>
using phpword
$styleTable = array('borderSize'=>1, 'borderColor'=>'006699');
$styleFirstRow = array('borderBottomSize'=>1, 'borderBottomColor'=>'0000FF');
$this->word->addTableStyle('myOwnTableStyle', $styleTable, $styleFirstRow);
// Add table
$table = $section->addTable('myOwnTableStyle');
Ref: http://www.ahowto.net/php/creating-ms-word-document-using-codeigniter-and-phpword
Upvotes: 0