2016-07-29 179 views
0

我有一个控制器功能,从视图中生成PDF。我想打印一个带有背景和背景白色部分内容的页面。我有点在第一页完美的措施,但我有两个问题:但我有两个问题:Laravel和DOMPDF - 设置内容边距

  • 在第二页的内容显示无边距,只是在页面的顶部。
  • 背景仅在第二页(内容完成时)打印其大小的一半。

这是HTML:

<div class="contenedor"> 
     <div class="cuerpo"> 
     <h3 style="margin: 20px 0;">Candidatos contratados a día {{ Date('d/m/Y') }}</h3> 
     <table class="table" style="border: 0;"> 
      <thead> 
      <tr style="text-transform: uppercase;"> 
       <th width="40%" style="background-color: #DBDBDB;">Candidato</th> 
       <th width="40%" style="background-color: #F1F1F1;">Posto</th> 
       <th width="20%" style="background-color: #F1F1F1;">Tipo</th> 
       <th width="5%" style="background-color: #F1F1F1;">Horas</th> 
      </tr> 
      </thead> 
      <tbody> 
      @foreach($clientes as $cliente) 
       <tr> 
       <td width="40%" style="background-color: #EBEDED;" data-title="Candidato">{{ $cliente->apellidos }}, {{ $cliente->nombre }}</td> 
       <td width="40%" data-title="Posto">{{ $cliente->puesto }}</td> 
       <td width="10%" data-title="Tipo">{{ $cliente->tipo }}</td> 
       <td width="10%" data-title="Horas">{{ $cliente->horas_semanales }}</td> 
       </tr> 
      @endforeach 
      </tbody> 
     </table> 
     </div> 
    </div> 

这是CSS代码

@page { 
    margin: 0; 
    } 
    *{ 
    color: #111; 
    } 
    body { 
    font-size: 11pt; 
    padding: 0; 
    margin: 0; 
    } 
    .contenedor{ 
    background-image: url('{{ URL::asset('images/fondo-imprimir.jpg') }}'); 
    background-repeat: no-repeat; 
    background-position: 0 0; 
    } 
    .background{ 
    position: fixed; 
    top: 0; 
    left: 0; 
    width: 595.276pt; 
    height: 841.89pt; 
    z-index: 1; 
    } 
    .background img{ 
    width: 100%; 
    height: auto; 
    } 
    .cuerpo{ 
    page-break-after: auto; 
    max-width: 484.725pt; 
    max-height: 635.275pt; 
    z-index: 10; 
    margin: 107.402pt 56.693pt 99.213pt 53.858pt; 
    } 
    tr { page-break-before: auto; max-height: 40pt; } 
    td{ 
    border-bottom: 1px dotted rgba(0,0,0,0.04); 
    } 
    #duracion, #completado{ display: none; } 

正如你所看到的,我设置页面和身体边距和补0。为了设置所有纸张中的背景以及.cuerpo div,边距margin: 107.402pt 56.693pt 99.213pt 53.858pt;设置在背景的空白部分。第一页的作品几乎完美,第二页不遵循这个规则。

回答

0

页面元素不会在页面间重复页边距(see issue #640)。您想要做的是将页边距设置为0并填充主体。

假设你.cuerpo div有正确的间距你可以尝试以下操作:

@page { 
    margin: 0; 
    } 
    *{ 
    color: #111; 
    } 
    body { 
    font-size: 11pt; 
    padding: 107.402pt 56.693pt 99.213pt 53.858pt; 
    margin: 0; 
    } 
    .contenedor{ 
    background-image: url('{{ URL::asset('images/fondo-imprimir.jpg') }}'); 
    background-repeat: no-repeat; 
    background-position: 0 0; 
    } 
    .background{ 
    position: fixed; 
    top: 0; 
    left: 0; 
    width: 595.276pt; 
    height: 841.89pt; 
    z-index: 1; 
    } 
    .background img{ 
    width: 100%; 
    height: auto; 
    } 
    .cuerpo{ 
    page-break-after: auto; 
    max-width: 484.725pt; 
    max-height: 635.275pt; 
    z-index: 10; 
    } 
    tr { page-break-before: auto; max-height: 40pt; } 
    td{ 
    border-bottom: 1px dotted rgba(0,0,0,0.04); 
    } 
    #duracion, #completado{ display: none; } 

至于半页的问题,这可能是与身体如何的高度被确定的问题(视在你的dompdf版本上)。添加有关您的dompdf版本的信息,我会更新此答案。