Forum


Replies: 1   Views: 170
How to make text bold and some part of that text would be superscript
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 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.