Get position of text in mPDF to determine vertical height of HTML element

混江龙づ霸主 提交于 2019-12-01 11:42:49

问题


I am generating PDFs with the mPDF class and wondering if and how would it be possible to determine the position of the last line of text in document that is generated mPDF?

I need an HTML box to be cover in height any remaining space between the last line of text and the bottom margin of the document. By setting the html element to height: 100% that pushes the element to the new page and covering the whole height of the new page.

The content of the page is generated dynamically based on a number of factors, so I can never be sure at which vertical position the last line will be at.

If I knew the vertical position of the last line, I could subtract the value from the total page height and then set by CSS the element to have that height.

Is that possible or are there other solutions?


回答1:


You can use for this purpose "$mpdf->y" (current position in user unit for cell positioning):

$mpdf=new mPDF('', 'A4');
$mpdf->WriteHTML('Line1<pagebreak>Line2<br>Line3');
//
$unusedSpaceH = $mpdf->h - $mpdf->y - $mpdf->bMargin;
$unusedSpaceW = $mpdf->w - $mpdf->lMargin - $mpdf->rMargin;
//
$mpdf->Rect($mpdf->x, $mpdf->y, $unusedSpaceW, $unusedSpaceH);
$mpdf->Output();


来源:https://stackoverflow.com/questions/29395455/get-position-of-text-in-mpdf-to-determine-vertical-height-of-html-element

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!