Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting text height to know fill height as in TCPDF

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 http://www.tcpdf.org/examples/example_005.pdf 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

http://pastebin.com/A1niGrQG

Anyone knows how to trace this, because doing it by hand and looking through the code isn't working at all for me.

like image 973
sami Avatar asked Oct 12 '25 14:10

sami


1 Answers

TCPDF (at least the latest version) includes the method getStringHeight() which get the estimated height needed for printing a simple text string using the Multicell() method. Additionally, the getNumLines() method gives you the estimatad number of lines. Check the source code documentation at http://www.tcpdf.org for further information.

like image 187
Nicola Asuni Avatar answered Oct 14 '25 04:10

Nicola Asuni