Forum


Replies: 6   Views: 2208
Display text with double underline
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 cmoller  · 26-03-2019 - 02:49

I am trying to figure out how to embed HTML text and display with a double underline. I have tried embedHTML with CSS styles to format with a double underline but it only displays the text with a single underline.

$docx = new CreateDocx();
$docx->embedHtml('<html><body><div id="content"><p>test <abbr style="text-decoration: underline; text-decoration-style: double;">abbr</abbr></p></div></body></html>');
$docx->createDocxAndDownload('result.docx');  
 

So I am trying now to use my own Double Underline word style. I have defined a style in the document word.docx for double underline and I can apply it as follows.

$docx = new CreateDocx();
$docx->importStyles('word.docx', 'merge', array('Double Underline'));
$docx->addText('This is some sample character test', array('rStyle' => 'DoubleUnderline'));

But when I try use the same word.docx template Double Underline style with embedHTML it doesn't work.

$docx = new CreateDocx();
$docx->importStyles('word.docx', 'merge', array('Double Underline'));
$wordStyles = array('.dblunderline' => 'DoubleUnderline');
$docx->embedHTML('<p class="dblunderline">my test</p>', array('strictWordStyles' => true, 'wordStyles' => $wordStyles));
$docx->createDocxAndDownload('result.docx');  

What am I missing?

Charlotte

 

Posted by admin  · 26-03-2019 - 07:29

Hello,

Maybe the style ID is not correct? You can get all style IDs from a DOCX using the parseStyles method. If you send the document (word.docx) to contact[at]phpdocx.com we'll check it.

Regards.

Posted by cmoller  · 26-03-2019 - 20:46

Tx! I did check the style id with parseStyles() and it looks to me to be DoubleUnderline as specified in

$wordStyles = array('.dblunderline' => 'DoubleUnderline');

if you are able to assist by checking my word.docx that would be much appreciated. I've emailled it to contact[at]phpdocx.com

Charlotte

Posted by admin  · 27-03-2019 - 07:38

Hello,

Thanks for attaching the file. The problem is that you are trying to apply a character style to a paragraph tag. Although addText allows it, the embedHTML can't apply it. You need to use a paragraph style, for example using a custom paragraph style (DocHeading4) from your document:

$docx->importStyles('word.docx', 'merge', array('DocHeading4'));

$wordStyles = array('.dblunderline' => 'DocHeading4');

$docx->embedHTML('<p class="dblunderline">my test</p>', array('strictWordStyles' => true, 'wordStyles' => $wordStyles));
$docx->createDocx('result.docx'); 

Please note that you can't apply a character style using embedHTML and a Basic license. You'd need to use HTML Extended available only in Premium licenses.

Regards.

Posted by cmoller  · 27-03-2019 - 14:51

Okay thanks. I actually need to double underline just a portion of a paragraph not the whole paragraph. So just to confirm, in order to do that I'd need the Premium license? There is no other way?

Posted by admin  · 27-03-2019 - 15:44

Hello,

The best and easiest solution is using a Premium license, that includes HTML Extended features. For this specific case, you can do a minor change in the library:

Edit HTML2WordML.php in the classes folder, and in the method generateRPr (around line 1859), add these lines after the line-through check:

if (isset($properties['text_decoration']) && $properties['text_decoration'] == 'double-underline') {
    $stringRPr .='<w:u w:val="double" />';
}

Instead of this code:

if (isset($properties['text_decoration']) && $properties['text_decoration'] == 'line-through') {
    $stringRPr .='<w:strike />';
}
if (!$this->strictWordStyles) {

this is the code updated:

if (isset($properties['text_decoration']) && $properties['text_decoration'] == 'line-through') {
    $stringRPr .='<w:strike />';
}
if (isset($properties['text_decoration']) && $properties['text_decoration'] == 'double-underline') {
    $stringRPr .='<w:u w:val="double" />';
}
if (!$this->strictWordStyles) {

After this change, you can use the custom double-underline value to apply a double underline style in texts:

$html = '
<style>
    .underline {
        text-decoration: underline;
    }
    .dunderline {
        text-decoration: double-underline;
    }
</style>
';
$html .= '<p><span class="underline">Underline</span> and <span class="dunderline">double underline</span>.</p>';
$docx->embedHTML($html);

Regards.

Posted by cmoller  · 29-03-2019 - 16:07

That works great, thank-you! Although my preference would be to purchase the Premium license, we are under some budget constraints so the workaround you provide for now is much appreciated.