barryvdh/laravel-dompdf分页符内容更改PDF [英] barryvdh/laravel-dompdf page break content changes PDF

查看:520
本文介绍了barryvdh/laravel-dompdf分页符内容更改PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此程序包barryvdh/laravel-dompdf是否有任何方法可以检测内容是否适合当前页面,如果内容不完全适合我可以将该内容放到下一页.

I am using this package barryvdh/laravel-dompdf is there any way to detect if content fits on the current page if not I want to put that content to the next page if it does not fit completly.

推荐答案

在有关所询问主题的文档中有这样的说法:

This is said in the documentation about the asked subject: https://github.com/barryvdh/laravel-dompdf

提示:分页符

您可以使用CSS page-break-before/page-break-after属性来创建新页面.

You can use the CSS page-break-before/page-break-after properties to create a new page.

<style>
.page-break {
    page-break-after: always;
}
</style>
<h1>Page 1</h1>
<div class="page-break"></div>
<h1>Page 2</h1>

更新,您可以遍历项目并在10格后调用例如:

<?php $i=0 ?>
@foreach($array as $object)
<?php $i++ ?>
    <!-- do something here | divs -->
    if( $i % 10 == 0 ){ 
        echo '<div class="page-break"></div>'; .... 
    }
@endforeach

您将必须确定自己可以显示多少个div来填满一个页面.例如,A4纸始终具有相同的高度,因此您可以猜测此页面上可以显示多少个div.

You will have to determine yourself how many divs you can show to fill a page. An A4 paper for example has always the same height so you could make a guess of how many of your divs can be displayed on this page.

这篇关于barryvdh/laravel-dompdf分页符内容更改PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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