barryvdh/laravel-dompdf 分页内容更改 PDF
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46728463/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
barryvdh/laravel-dompdf page break content changes PDF
提问by shkurta
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.
我正在使用这个包 barryvdh/laravel-dompdf 是否有任何方法可以检测内容是否适合当前页面,如果不适合我想将该内容放到下一页,如果它不完全适合。
回答by Lars Mertens
This is said in the documentation about the asked subject: https://github.com/barryvdh/laravel-dompdf
这是在关于所问主题的文档中说的:https: //github.com/barryvdh/laravel-dompdf
Tip: Page breaks
提示:分页符
You can use the CSS page-break-before/page-break-after properties to create a new page.
您可以使用 CSS page-break-before/page-break-after 属性来创建新页面。
<style>
.page-break {
page-break-after: always;
}
</style>
<h1>Page 1</h1>
<div class="page-break"></div>
<h1>Page 2</h1>
Update, you can iterate through the items and call for example after 10 divs:
更新,您可以遍历项目并在 10 个 div 后调用:
<?php $i=0 ?>
@foreach($array as $object)
<?php $i++ ?>
<!-- do something here | divs -->
if( $i % 10 == 0 ){
echo '<div class="page-break"></div>'; ....
}
@endforeach
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.
您必须自己确定可以显示多少个 div 来填充页面。例如,一张 A4 纸的高度始终相同,因此您可以猜测此页面上可以显示多少个 div。