Forum


Replies: 1   Views: 520
Get inline styles for a custom styled text
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 akhil  · 28-04-2023 - 03:17

Hi,

I have a custom style which defines the text to be bold and font-family to be Time New Roman. I applied this paragraph style to a paragraph and selected the paragraph and changed the font-family of the paragraph to 'Calibri' and font to be not bold. The xml of this paragraph looks like below.

<w:p w14:paraId="219DFD1A" w14:textId="2C1F85A0" w:rsidR="00CB7771" w:rsidRPr="00A43B53" w:rsidRDefault="00C458EA" w:rsidP="00CB7771">
         <w:pPr>
            <w:pStyle w:val="Question" />
            <w:numPr>
               <w:ilvl w:val="0" />
               <w:numId w:val="31" />
            </w:numPr>
            <w:spacing w:before="0" w:after="0" w:line="240" w:lineRule="auto" />
            <w:rPr>
               <w:rFonts w:asciiTheme="minorHAnsi" w:hAnsiTheme="minorHAnsi" w:cstheme="minorHAnsi" />
               <w:b w:val="0" />
               <w:szCs w:val="22" />
            </w:rPr>
         </w:pPr>
         <w:r w:rsidRPr="00EA56BD">
            <w:rPr>
               <w:rFonts w:asciiTheme="minorHAnsi" w:hAnsiTheme="minorHAnsi" w:cstheme="minorHAnsi" />
               <w:b w:val="0" />
            </w:rPr>
            <w:t>Hello Is this a bug?</w:t>
         </w:r>
      </w:p>

After parsing, the text is still being identified as bold, though I had selected that text specifically to be not bold and the same with font family. If the style definition had not mentioned any font style as well as font family, the inline style does get picked up. However, if the paragraph style had defined it, the inline style does not get picked up.
Is there any known fix for this, rather than patching the library?
Also, the font-family name does not show up in <w:rFonts tag. The way Calibri can be pickup is by looking up <a:minorFont> tag in theme1.xml. Is there a helper function to look this up?

Posted by admin  · 28-04-2023 - 05:41

Hello,

We have done some quick tests and everything is working correctly when updating the styles. We have generated a DOCX with a custom style that sets a bold style and uses the default font. Using DOCXCustomizer:

$referenceNode = array(
    'type' => 'paragraph',
    'occurrence' => 1,
);

$docx->customizeWordContent($referenceNode,
    array(
        'bold' => false,
        'font' => 'Times New Roman',
    )
);

the bold style is disabled and Times New Roman is set as the font in MS Word and using phpdocx methods (the same if we done the changes manually).

If you send to contact[at]phpdocx.com a DOCX we'll check it and generate a custom sample script. If you also sent the phpdocx code you are running to change the styles we'll check it too.

Regards.