Search code examples
phptcpdffpdf

TCPDF - How to use GetStringWidth when text is bold


Is there a way to use GetStringWidth on text that has formatting? Right now if I have <b>Jarod</b>, the GetStringWidth treats the tags as if they are text to display and returns the string width including the tags. If I take them out, then the String Width returned is for non-bold text and we know that bold text is bigger than non-formatted text, so I'm trying to figure out how to measure formatted text width in TCPDF. Thanks!


Solution

  • According TCPDF Doc you can send parameters to the GetStringWidth() function, including font style. In your example:

    $text_width = $pdf->GetStringWidth("Text To Be Measured",'','B');