如何在Dompdf laravel 5.5中使用分页符?

时间:2018-11-06 05:45:21

标签: php css laravel laravel-5.5 dompdf

我在设计系统pdf时遇到问题。这是我的pdf图片:

PDF FILE

我想做的是将表中的项目数限制为10个,然后其余部分转到页眉和页脚已固定的下一页。像这样: Purchase Request PDF

这是我的代码:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <title>PDF</title>

    <link href="{{ asset('css/bootstrap.min.css') }}" rel="stylesheet">
    <style>
        #items tr{border:1px solid #000000;}
        #items tbody tr td{border:1px solid #000000;}
        #items thead td{background-color:#231F20;color:#FFFFFF;}

        .header { position: fixed; left: 0px; top: -40px; right: 0px;}
        .footer { position: fixed; left: 0px; bottom: 200px; right: 0px;}
    </style>
    <link rel="stylesheet" href="{{ asset('css/lato.css') }}">
    <link href="https://fonts.googleapis.com/css?family=Libre+Barcode+128" rel="stylesheet">



</head>
<body>
<div class="container-fluid">

<div class="header">
    <div class="row">

        <div class="col-xs-3" style="font-family: 'Libre Barcode 128', cursive; font-size: 35px;padding: 10px 0px 0px 0px;">{{$pr->pr_form_no}}</div>
        <div class="col-xs-9">
        <table cellspacing='0' cellpadding='5' style="border-width: 0 !important;padding:0px 0px 0px 60px;">
            <tr>
                <td style="padding: 10px;"><img src="{{asset('images/sfclogo.png')}}" width="50px" height="50px"></td>
                <td>
                    <table style="text-align: center;style='width:45%'">
                        <tr><td>REPUBLIC OF THE PHILIPPINES</td></tr>
                        <tr><td>PROVINCE OF LA UNION</td></tr>
                        <tr><td>CITY OF SAN FERNANDO</td></tr>
                    </table>
                </td>
                <th style="padding-top: 10px;padding-left: 10px"><p style="background-color: #000;color: #FFF; text-align: center;padding: 10px;">PR</p></th>
            </tr>
        </table>
        </div>
    </div>

      <div class="row">
        <div class="col-md-12" style="text-align: center;color: white;background-color: black; font-size: 18px">
            PURCHASE REQUEST
        </div><br>
      </div>

      <div class="row">
                <table style='width:100%;border:1px solid #000000;font-size:11pt;' cellspacing='0' cellpadding='5' class='font1'>
                <tr>
                    <td style='width:40%'>
                        <table style='width:90%;padding-right: 0px;' cellpadding='0' cellspacing='0'>
                            <tr>
                                <td style='width:100%;padding:1px;padding-left:10px;' colspan='2'>DEPARTMENT:</td>
                            </tr>
                            <tr>
                                <td style='width:100%;padding:0px;padding-left:10px;' colspan='2'>{{$dept->office_name}}<hr style='color:#000000;height:1px;margin-bottom:3px;margin-top:0px;padding-left:10px;' /></td>
                            </tr>
                            <tr>
                                <td style='width:15%;padding:1px;padding-left:10px;'>SECTION:</td>
                                <td style='width:75%;padding:0px;padding-left:0px;'>{{$section->office_name}}<hr style='color:#000000;height:1px;margin-bottom:3px;margin-top:0px;' /></td>
                            </tr>
                        </table>
                    </td>
                    <td style='width:30%;'>
                        <table style='width:90%;' cellpadding='0' cellspacing='0'>
                            <tr>
                                <td style='width:20%;padding:1px;'>PR No.</td>
                                <td style='width:70%;padding:0px;border-bottom:1px solid #000000;'>{{$pr->pr_form_no}}</td>
                            </tr>
                            <tr>
                                <td style='width:20%;padding:1px;'>SAI No.</td>
                                <td style='width:70%;padding:0px;border-bottom:1px solid #000000;'></td>
                            </tr>
                            <tr>
                                <td style='width:20%;padding:1px;'>ObR No.</td>
                                <td style='width:70%;padding:0px;border-bottom:1px solid #000000;'></td>
                            </tr>
                        </table>
                    </td>
                    <td style='width:30%'>
                        <table style='width:95%;' cellpadding='0' cellspacing='0'>
                            <tr>
                                <td style='width:15%;padding:1px;'>Date</td>
                                <td style='width:70%;padding:0px;border-bottom:1px solid #000000;'>&nbsp;{{$dt->toFormattedDateString()}}</td>
                            </tr>
                            <tr>
                                <td style='width:15%;padding:1px;'>Budget</td>
                                <td style='width:70%;padding:0px;border-bottom:1px solid #000000;'><strong>&nbsp;PHP {{number_format($pr->budget_alloc,2)}}</strong></td>
                            </tr>
                            <tr>
                                <td style='width:15%;padding:1px;'>Supplier</td>
                                <td style='width:70%;padding:0px;border-bottom:1px solid #000;'>&nbsp;{{$pr->supplier_type}}</td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
      </div>
  </div>

 <div class="footer">
    <div class="row">
        <table style='width:100%;border:1px solid #000000;font-size:12px;margin-left:auto;margin-right:auto;margin-top:40px;' cellspacing='0' cellpadding='3' class='font1'>
            <tr>
                <td style='width:39%; font-weight:bold;text-align:left;border:1px solid #000000;'>
                REQUESTING OFFICE<br/><br/><br/><br/>
                </td>
                <td style='width:60%;border:1px solid #000000;vertical-align:top;font-weight:bold;' colspan='2' rowspan='3'>
                PURPOSE<br/>
                <div style='width:100%;text-align:center;font-weight:normal;font-size:11pt;' class='font1'>
                    {{$pr->purpose}}
                </div>
                </td>
            </tr>
            <tr>
                <td style='border:1px solid #000000;height:19px;text-align:center;text-transform:uppercase;font-weight:bold;'>
                {{$pr->requestor_name}}
                </td>
            </tr>
            <tr>
                <td style='text-align:center;border:1px solid #000000;text-transform:uppercase;height:19px;font-weight:bold'>
                {{$pr->requestor_position}}
                </td>
            </tr>
            <tr>
                <td colspan='3' style='background-color:#000000;height:20px;'>
            </tr>
            <tr>
                <td style='width:33%; font-weight:bold;text-align:left;border:1px solid #000000;'>
                APPROPRIATION AVAILABLE
                </td>
                <td style='width:33%; font-weight:bold;text-align:left;border:1px solid #000000;'>
                FUNDS AVAILABLE
                </td>
                <td style='width:33%; font-weight:bold;text-align:left;border:1px solid #000000;'>
                APPROVED
                </td>
            </tr>
            <tr>
                <td style='border:1px solid #000000;height:25px;text-align:center;text-transform:uppercase;font-weight:bold;'>

                </td>
                <td style='border:1px solid #000000;height:25px;text-align:center;text-transform:uppercase;font-weight:bold;'>

                </td>
                <td style='border:1px solid #000000;height:25px;text-align:center;text-transform:uppercase;font-weight:bold;'>

                </td>
            </tr>
            <tr>
                <td style='width:33%; font-weight:bold;text-align:center;border:1px solid #000000;text-transform:uppercase;'>
                {{$aa->name}}<br/>
                {{$aa->position}}
                </td>
                <td style='width:33%; font-weight:bold;text-align:center;border:1px solid #000000;text-transform:uppercase;'>
                {{$c->name}}<br/>
                {{$c->position}}
                </td>
                <td style='width:33%; font-weight:bold;text-align:center;border:1px solid #000000;text-transform:uppercase;'>
                {{$approval->name}}<br/>
                {{$approval->position}}
                </td>
            </tr>
        </table>
    </div>
    <div class="row">
        <div style='float:left;font-weight:normal;font-style:italic;font-size:7pt;width:40%;text-align:left;'>{{$created_code}}</div>
    </div>
</div>

<div class="content" >
      <div class="row">
        <table style='width:100%;font-size:14px;text-align:center;border:1px solid #000000;' id='items'  cellpadding='0' cellspacing='0'>

            <thead>
                <tr>
                    <td style='width:7%;font-weight:bold;'>ITEM NO.</td>
                    <td style='width:7%;font-weight:bold;'>QTY</td>
                    <td style='width:7%;font-weight:bold;'>UNIT</td>
                    <td style='width:49%;font-weight:bold;'>DESCRIPTION</td>
                    <td style='width:15%;font-weight:bold;'>ESTIMATED UNIT OF</td>
                    <td style='width:15%;font-weight:bold;'>ESTIMATED COST</td>
                </tr>
            </thead>    

            <tbody >
                @foreach($list as $indexKey => $list)

                <tr>
                  <td>{{$indexKey}}</td>
                  <td>{{$list->pr_qty}}</td>
                  <td>{{$list->pr_unit}}</td>
                  <td>{{$list->pr_description}}</td>
                  <td  style='text-align: right;'>{{$list->pr_cost_per_unit}}</td>
                  <td style='text-align: right;'>{{$list->pr_estimated_cost}}</td>
                </tr>

                @if($indexKey >= 9)
                        @break
                @endif

                @endforeach

                @for($i = $count; $i < 10; $i++)
                    <tr><td>&nbsp;</td><td>&nbsp;</td>&nbsp;<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
                @endfor

            </tbody>

            <tfoot>
                <tr style="background-color: #b0b1b2;">
                  <td colspan="5" style="text-align: right; font-weight: bold;">GRAND TOTAL</td>
                  <td style="text-align: right; font-weight: bold;">
                    {{number_format($grand_total,2)}}
                  </td>
                </tr>
            </tfoot>
        </table>
      </div>
  </div>



</div>

<script src="{{ asset('js/jquery.min.js') }}"></script>
<script src="{{ asset('js/bootstrap.min.js') }}"></script>
</body>
</html>

当显示的项目已经是10个时,我已经尝试使用刀片的break功能来停止循环。

*如果代码看起来像地狱,也很抱歉。

1 个答案:

答案 0 :(得分:2)

您可以使用一些CSS样式,如下所示:

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

如果要在例如5个div后进行分页,则可以执行以下操作:

@php $check=0 @endphp
@foreach($array as $item)
@php $check++ @endphp
  <!-- your code or something like divs -->
@if( $check % 5 == 0 ) 
     @php echo '<div class="page-break"></div>'; @endphp .... 
 @endif
@endforeach

希望您会从中得到灵感。