Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Just as a very simple proof of concept for what i said in my last comment on my other answer...</p> <p>** You need to use a <strong>monospaced</strong> font and a line height equal to your text height (that or modify the code for line height instead of text height) fairly simple fix...</p> <p>You also have to figure out your aproximate monospaced width.. Best thing to do is use a capitol M (M is the widest char - so monospaced chars are set to this width..)</p> <pre><code>&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body style="font-family:'Courier New', Courier, monospace; line-height:12px;"&gt; &lt;?php //If you are using a monospace font, this kinda works $divWidth = 300; // in px; $fontSize = 12; // (in px); $fontWidth = 7; // in px - aprox monospace font width $lineChars = floor($divWidth / $fontWidth); $text = &lt;&lt;&lt;EOT MMMMMMMMMM (capital M is the widest character)I'm trying to go through the code of TCPDF to understand how it calculates the height of the text to be rendered, but it's too much for me to handle without asking. What I want to know: in the PDF from example 5 it gives the cell a yellow background. I'm guessing that at the basic level, it first draws a box with this fill color, then adds the text, so what method is it calling to get the height of the text to know the height of the box to fill? I can see from the example code that MultiCell() is the entry point, but it's not clear what's the method it calls to get the height of the text. I pasted the code for MultiCell() in this pastebin EOT; $wrappedText = wordwrap($text, $lineChars, "LINEHERE"); $lines = substr_count($wrappedText, "LINEHERE"); $newlines = substr_count($text, "\n"); $text = str_replace("\n", "&lt;br&gt;",$text); $lines += $newlines; $divHeight = $lines * $fontSize; echo "With a width of: " . $divWidth . "&lt;br&gt;"; echo "Number of Lines: " . $lines . "&lt;br&gt;"; echo "Height Required: " . $divHeight . "px&lt;br&gt;"; echo "Wrapped Text at: " . $lineChars . " characters&lt;br&gt;&lt;br&gt;"; $divsize = "width:$divWidth px; height:$divHeight px; font-size:$fontSize px; "; $outStr = "&lt;div style='overflow:auto; display:inline-block; background-color:aqua; $divsize'&gt;$text&lt;/div&gt;"; $outStr .= "&lt;div style=' display:inline-block; background-color:fuchsia; $divsize'&gt;&amp;nbsp;&lt;/div&gt;"; echo $outStr; ?&gt; &lt;/body&gt;&lt;/html&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload