PHPWord
PHPWord copied to clipboard
Paragraph styling isn't recognised
Describe the Bug
Using TemplateProcessor, I'm unable to set paragraph styling (in other words, setting line-height). It doesn't seem to react to it whatsoever.
However, FontStyle works just fine.
This happens while using TextRun()->addText().
Steps to Reproduce
Please provide a code sample that reproduces the issue.
<?php
$template = new \PhpOffice\PhpWord\TemplateProcessor('mytemplate.docx');
$txtContent = new \PhpOffice\PhpWord\Element\TextRun();
$desc = "Hello, World!";
$body_txt_style = array();
$txtContent->addText($desc, $body_txt_style, $body_pg_style);
$template->setComplexBlock("description_body", $txtContent);
Expected Behavior
A line-height of 1.5 should be visible on the text that has been outputted in the document.
Current Behavior
Line height remains at 1.0 and even ignores the line-height of the template variable (which is set to 1.5)
Context
Please fill in your environment information:
- PHP Version: 7
- PHPWord Version: 0.18.2
I'm not sure if this is a bug as much as insufficient documentation.
I was having the issue and dove into the code, The TextRun element translates to a paragraph element, so you would have to apply the paragraph styles to the TextRun.
<?php
$template = new \PhpOffice\PhpWord\TemplateProcessor('mytemplate.docx');
$txtContent = new \PhpOffice\PhpWord\Element\TextRun(['lineHeight' => 1.0]);
$desc = "Hello, World!";
$txtContent->addText($desc);
$template->setComplexBlock("description_body", $txtContent);
@skeemer Hi, Could you send the template, please ?
Sorry, I can't. I've never used templates, just adapted the OP's code to something similar to what I tested.