Forum


Replies: 1   Views: 126
How to make text bold and some part of that text would be superscript

Posted by admin  · 26-09-2024 - 10:28

Hello,

addText (https://www.phpdocx.com/api-documentation/word-content/add-paragraph-text-Word-document-with-PHP) includes the superscript option to add text in superscript:

$text = array();
$text[] =
    array(
        'text' => 'A bold text',
        'bold' => true,
);
$text[] =
    array(
        'text' => ' superscript content',
        'superscript' => true,
);
$docx->addText($text);

If you are using HTML tags to add contents, you need to use embedHTML or replaceVariableByHTML to transform HTML to DOCX.
You can get the same output using CSS styles (as inline, external, or style tags):

$html = '<p><span style="font-weight: bold;">A bold text</span><span style="vertical-align: super;">superscript content</span></p>';
$docx->embedHTML($html);

or using tags:

$html = '<p><b>A bold text</b><sup>superscript content</sup></p>';
$docx->embedHTML($html);

Regards.