MPDF 将 2 条线保持在一起

发布于 2024-11-25 07:35:41 字数 2453 浏览 0 评论 0原文

在使用 PHP PDF 生成库 MDPF 时,我遇到了一个必须克服的限制。首先我遇到了这个:

Nullam sagittis varius ligula,在 blandit tortor pharetra quis。整数 faucibus dui sed totortor fringilla a laoreet Tellus sollicidin。 Sed dapibus、 eros a dapibus lobortis、 eros Tellus volutpat Massa、 eget scelerisque mi lectus et neque。 Praesent faucibus tempus nibh,ac tempus ante facilisis vitae。 Proin risus diam, egestas id interdum et, consectetur eu sapien.

Lorem ipsum dolor sat amet,consectetur adipiscing elit。菜豆 (Phasellus rut​​rum cursus dolor), ut sollicitudin lacus faucibus at。暂停效力。 Duis iaculis lacus et quam hendrerit vel celerisque justo 前庭。 Fusce faucibus bibendumerat,vitae convallis elit blandit non。爱琴海的尊严

--分页符--

eleifend ac vitae nisl。

这被认为是“寡妇”。所以我发现添加CSS“page-break-inside:avoid;”如果该段落不合适,则将其移至该段落。上面的内容将变成:

Nullam sagittis varius ligula,位于 blandit totorpharetra quis。整数 faucibus dui sed totortor fringilla a laoreet Tellus sollicidin。 Sed dapibus、 eros a dapibus lobortis、 erostellus volutpat Massa、 eget scelerisque mi lectus et neque。 Praesent faucibus tempus nibh,ac tempus ante facilisis vitae。 Proin risus diam, egestas id interdum et, consectetur eu sapien.

--分页符--

Lorem ipsum dolor sat amet,consectetur adipiscing elit。菜豆 (Phasellus rut​​rum cursus dolor), ut sollicitudin lacus faucibus at。暂停效力。 Duis iaculis lacus et quam hendrerit vel celerisque justo 前庭。 Fusce faucibus bibendumerat,vitae convallis elit blandit non。 Aenean dignissim eleifend ac vitae nisl。

但这也是一个问题,因为有时会在页面底部留下大量空白空间。我需要能够将两行保持在一起,这样如果它必须在段落结束之前中断页面,它会将下一页上的最后两行保持在一起,如下所示:

Nullam sagittis varius ligula,位于 blandit totorpharetra quis。整数 faucibus dui sed totortor fringilla a laoreet Tellus sollicidin。 Sed dapibus、 eros a dapibus lobortis、 eros Tellus volutpat Massa、 eget scelerisque mi lectus et neque。 Praesent faucibus tempus nibh,ac tempus ante facilisis vitae。 Proin risus diam, egestas id interdum et, consectetur eu sapien.

Lorem ipsum dolor sat amet,consectetur adipiscing elit。菜豆 (Phasellus rut​​rum cursus dolor), ut sollicitudin lacus faucibus at。暂停效力。 Duis iaculis lacus et quam hendrerit vel scelerisque

--分页符--

刚刚前庭。 Fusce faucibus bibendumerat,vitae convallis elit blandit non。 Aenean dignissim eleifend ac vitae nisl。

知道如何让 MPDF 做到这一点吗?我知道它不是内置的,但如果有人知道我会在哪里开始添加此功能,那将会很有帮助。

In using the PHP PDF generation library MDPF I ran into a limitation which I have to get past. First I ran into this:

Nullam sagittis varius ligula, at blandit tortor pharetra quis. Integer faucibus dui sed tortor fringilla a laoreet tellus sollicitudin. Sed dapibus, eros a dapibus lobortis, eros tellus volutpat massa, eget scelerisque mi lectus et neque. Praesent faucibus tempus nibh, ac tempus ante facilisis vitae. Proin risus diam, egestas id interdum et, consectetur eu sapien.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus rutrum cursus dolor, ut sollicitudin lacus faucibus at. Suspendisse potenti. Duis iaculis lacus et quam hendrerit vel scelerisque justo vestibulum. Fusce faucibus bibendum erat, vitae convallis elit blandit non. Aenean dignissim

--page break --

eleifend ac vitae nisl.

Which is considered a "widow." So I found that adding the CSS "page-break-inside: avoid;" carries the paragraph over if it doesn't fit. The above would become:

Nullam sagittis varius ligula, at blandit tortor pharetra quis. Integer faucibus dui sed tortor fringilla a laoreet tellus sollicitudin. Sed dapibus, eros a dapibus lobortis, eros tellus volutpat massa, eget scelerisque mi lectus et neque. Praesent faucibus tempus nibh, ac tempus ante facilisis vitae. Proin risus diam, egestas id interdum et, consectetur eu sapien.

--page break --

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus rutrum cursus dolor, ut sollicitudin lacus faucibus at. Suspendisse potenti. Duis iaculis lacus et quam hendrerit vel scelerisque justo vestibulum. Fusce faucibus bibendum erat, vitae convallis elit blandit non. Aenean dignissim eleifend ac vitae nisl.

This is also a problem though because it would leave a lot of empty space sometimes at the bottom of a page. I need to be able to keep 2 lines together so that if it has to break the page before a paragraph ends, it keeps the last 2 lines together on the next page like so:

Nullam sagittis varius ligula, at blandit tortor pharetra quis. Integer faucibus dui sed tortor fringilla a laoreet tellus sollicitudin. Sed dapibus, eros a dapibus lobortis, eros tellus volutpat massa, eget scelerisque mi lectus et neque. Praesent faucibus tempus nibh, ac tempus ante facilisis vitae. Proin risus diam, egestas id interdum et, consectetur eu sapien.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus rutrum cursus dolor, ut sollicitudin lacus faucibus at. Suspendisse potenti. Duis iaculis lacus et quam hendrerit vel scelerisque

--page break --

justo vestibulum. Fusce faucibus bibendum erat, vitae convallis elit blandit non. Aenean dignissim eleifend ac vitae nisl.

Any idea how to get MPDF to do this? I know it's not built in but if anyone has any idea where I would even start adding this feature that would be helpful.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故人的歌 2024-12-02 07:35:41

设置autoPageBreak

$mpdf->autoPageBreak = false;

set autoPageBreak

$mpdf->autoPageBreak = false;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文