Closed crosslogic closed 5 years ago
I want to reduce the size to fit inside the cell
pdf.GetStringWidth()
is really useful for this.
The loop below will take $str
, your string to fit, and $targetWidth
the cell width. (Assuming you know this value) It'll reduce the font size until it fits within.
pdf.SetFontSize(72)
for pdf.GetStringWidth(str) > targetWidth {
fontSize, _ := pdf.GetFontSize()
fontSize -= 0.25
pdf.SetFontSize(fontSize)
}
It doesn't handle newlines, and definitely could be optimised. Choose your start font size and step amounts wisely!
Please reopen if this is still an issue.
Is there anyway to keep the text inside the cell if it's too long?
I want to reduce the size to fit inside the cell, or cutting the part that overflows.