我正在使用mPDF library。
我正在尝试为给定的字符串确定最大的字体大小,以使其适合固定宽度/高度且在一行内的
示例:
$pdf->WriteHTML('<div style="font-size: 11px; width: 500px; height: 25px; line-height: 25px; border: 1px solid red;">This text is too long so it will not fit within 500px but what font-size would allow to avoid line breaks?</div>');
您可以看到font-size:11px不能完成工作,但是使用10px可以工作:
如何自动确定适合该div一行的最佳字体大小?
使用fPDF,您可以使用GetStringWidth()
和GetStringHeight()
来确保您的文本宽度/高度适合您的单元格,但mPDF不再可用。
到目前为止我尝试过的事情: