Forum


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

Posted by fairshareitservices  · 26-09-2024 - 08:14

Hi,

I am getting dynamic text from the input file and i need to convert that text to which is enclosed in <b> </b> to bold and there is some text remaining after </b> need to be converted into superscript. For bold i already using below code so how to modify this for superscript

function formatText($inputText,$templateDocx,$placeHolderName){
$docx = new CreateDocx();
$wf = new WordFragment($docx);
 $inputExploded=explode('</b>',$inputText);
foreach ($inputExploded as $key => $partialInput) {

        $partialInputExploded = explode('<b>', $partialInput);

        // Check if we need to add a line break
        if (!empty($partialInputExploded[0])) {
            // Split on <br> tags and handle accordingly
            $lineBreakArray = explode('<br>', $partialInputExploded[0]);
            foreach ($lineBreakArray as $key => $lineBreakText) {
                if (!empty($lineBreakText)) {                    
                    $text[] = array(
                        'text' => $lineBreakText,
                        'lineBreak' => 'after',
                    );                    
                }
            }
        }
           for ($i = 1; $i < count($partialInputExploded); $i++) {
              $text[] = array(
                    'text' => $partialInputExploded[$i],
                    'bold' => true,
                    'fontSize' => 7,
                    'font' => 'Cambria',
                );
            $wf->addText($text, array('font' => 'Cambria', 'fontSize' => 7));
         }

       return $wf;
}