Forum


Replies: 1   Views: 215
Line height and styles
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 tbuckland@hrdownloads.com  · 02-04-2019 - 18:48

I'm having a problem where documents are converting in a manner where the page heading is applying the wrong line-height, causing multiple lines of text to overlap. This is resulting in all HTML documents having a squished heading, along with some less noticeable issues. The styles that are being applied appear to be set in pixels. The documents being converted are primarily being supplied by the end user, so it is difficult to rely on good source documents.

I have tried using importStyles() to replace the docx settings but didn't see any results. I'm not sure whether this is the correct solution, or whether I should do something else to normalize the text styles.

The fixed line-height doesn't appear to be set anywhere in the original document. The heading font appears similar to Heading 1 PHPDOCX.

A few questions:
1) Are the undesirable styles coming from a phpdocx template or somewhere else?
2) What method should be used to address the styles? Add them through importStyles(), change the base template, or some other method?
3) Similar problems happen with nested styles. Is there a particular method to clean the markup?

Posted by admin  · 03-04-2019 - 10:01

Hello,

The line-height is applied based on the twips. If documents are using a w:lineRule with atLeast value, then the line-height may be very low.

To prevent this, we recommend you to apply the following change:

In the TransformDocAdvHTML.php file, go to the addPprStyles method, and instead of:

if ($pprStyle->hasAttribute('w:line')) {
    $styles .= 'line-height: ' . $this->htmlPlugin->transformSizes($pprStyle->getAttribute('w:line'), 'twips') . ';';
}

You can use:

if ($pprStyle->hasAttribute('w:line')) {
    if (!$pprStyle->hasAttribute('w:lineRule')) {
        $styles .= 'line-height: ' . $this->htmlPlugin->transformSizes($pprStyle->getAttribute('w:line'), 'twips') . ';';
    }
}

That prevents adding the line-height if w:lineRule is set.

You can also use DOCXCustomizer and getWordStyles to read, parse and change/normalize existing styles if needed.

Regards.