获取文本在mPDF中的位置,以确定HTML元素的垂直高度 [英] Get position of text in mPDF to determine vertical height of HTML element

查看:400
本文介绍了获取文本在mPDF中的位置,以确定HTML元素的垂直高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用mPDF类生成PDF,并且想知道是否以及如何确定生成mPDF的文档中文本的最后一行的位置?

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?

我需要一个HTML框来覆盖文本的最后一行和文档底边之间的所有剩余空间.通过将html元素设置为 height:100%,将元素推到新页面并覆盖新页面的整个高度.

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.

如果我知道最后一行的垂直位置,则可以从页面总高度中减去该值,然后由CSS将该元素设置为具有该高度.

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?

推荐答案

为此,您可以使用"$ mpdf-> y"(用户单元中用于单元格定位的当前位置):

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();

这篇关于获取文本在mPDF中的位置,以确定HTML元素的垂直高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆