PHPWord icon indicating copy to clipboard operation
PHPWord copied to clipboard

Paragraph styling isn't recognised

Open nesben opened this issue 3 years ago • 3 comments

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

nesben avatar Jun 10 '21 13:06 nesben

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 avatar Feb 16 '24 22:02 skeemer

@skeemer Hi, Could you send the template, please ?

Progi1984 avatar Feb 18 '24 12:02 Progi1984

Sorry, I can't. I've never used templates, just adapted the OP's code to something similar to what I tested.

skeemer avatar Feb 18 '24 14:02 skeemer