2016-09-20 5 views
0

Я генерации файла в формате PDF с использованием domppdf, вот мой HTML и CSS для макета в формате PDF:Как добавить «новую страницу» в DOMPDF автоматически

<html> 
<head> 

<style type="text/css"> 
.boxtest{ 
     height: 90px; 
     width: 270px; 
     background: #AAA; 
     font-size: 48px; 
     font-style: oblique; 
     color: #999; 
     text-align: center; 
     margin-top: 20px; 
     margin-left: 5px; 
    } 

table 
{ 
    width: 100%; 
} 

th 
{ 
    background-color: #BBB; 
    height: 50px; 
} 

td 
{ 
    text-align: center; 
} 

/*tr:hover {background-color: #f5f5f5}*/ 
tr:nth-child(even) 
{ 
    background-color: #f2f2f2;border:4px solid #73AD21; 
} 

tr 
{ 
    border:4px solid #73AD21 
} 

.table-title 
{ 
    background-color: #EEE; 
    position:fixed; 
    top:0em; 
} 

.table-content- 
{ 
    position:fixed; 
    top:2.5em; 
    font-style: sans-serif; 
} 

h3, div 
{ 
    font-family: sans-serif; 
} 


.company-logo 
{ 
    position: absolute; 
    float:left; 
    margin-left: 1em; 
    top:0; 
    left:1em; 
} 
.cover-text 
{ 
    position:absolute; 
    top:7em; 
    margin: 8em 4em 4em; 
    text-align: justify; 
    page-break-after: always; 
} 

.footer 
{ 
    width:100%; 
    position:fixed; 
    bottom:37px; 
    text-align: center; 
    font-size: 13px; 
} 

.page_number 
{ 
    width:100%; 
    position:fixed; 
    bottom:17px; 
    text-align: center; 
    font-size: 11px; 

} 

.page_breaking 
{ 
    position:absolute; 
    bottom: 0px; 
    page-break-after: always; 
} 

.page_number:before { content: counter(page); } 

@page 
{ 
    margin:0; 
    padding: 0; 
} 


</style> 
</head> 

<body> 
<div class="footer" align="center" style="font-family: sans-serif;"> Powered by Hyosoka Poipo, 2016 </div> 
<div class="page_number"></div> 


<div style="background-color: #353535; max-width:200%; margin:0; padding:0" > 
    <div style="color: white; margin-top:20px; margin-bottom: 20px;"> 
    <div align="center"><img src="img//-logo.png" alt=" Logo"/></div> 
    <div align="center"><h3 > {{$Title}} </h3> </div> 
    <div align="center"><h3><?php echo date("M-d, Y"); ?> </h3></div> 
    </div> 
</div> 


<div class="cover-text row" align="left"> 
    <p> COVER TEXT </p> 
    {{$CoverText}} 
</div> 



<div class="table-title" align="center" style="font-size:34px;"> 
TABLE OF REPORT 
</div> 


<table class="table table-condensed table-bordered table-hover table-content- "> 
    <thead> 
    <tr> 
    <th>No</th> 
    <th>Candidate</th> 
    <th>Rating</th> 
    @if($Comment != "false")<th>Comment</th>@endif 
    @if($Num == 99)<th>Status</th>@endif 
    </tr> 
    </thead> 

<tbody> 
     <?php $number = 1 ?> 
    @foreach($H as $candi) 
     <tr > 
     <td><?php echo $number++ ?></td> 
     <td style="text-align:left;"><b>{{$candi->fullname}}</b><br><div style="font-size:13px">{{$candi->phone}} {{$candi->email}}<br>{{$candi->location}}</div></td> 
     <td>{{$candi->rating}}</td> 
     @if($Comment != "false")<td><div>{{$candi->comment}}</div></td>@endif 
     @if($Num == 99)<td><div>{{RHelper::Type($candi->status)}}</div></td>@endif 
     </tr> 
     {{-- The problem is in here... If the loop is big, then dompdf just generate 1 page and forget the rest of the loop --}} 
     @endforeach 


    </tbody> 
</table> 

</body> 
</html> 

Проблема заключается в петле, если я есть много данных, DOMPDF просто генерировать 1 страницу для меня, как показано ниже:

enter image description here So ... Как автоматически создать новую страницу в DOMPDF, чтобы показать все доступные данные из моего цикла. Я пытался добавить код ниже в то конец моего HTML

.page_breaking 
{ 
    position:absolute; 
    bottom: 0px; 
    page-break-after: always; 
} 

{{-- <div class="page_breaking"></div> --}} 

Это не работает для меня, потому что на странице, цикл начинается с начала. А также я пытался поставить

style="page-break-after: always;" 

Когда индекс reachs определенное значение, но это не работает для меня тоже, потому что запрос стал тайм-аут. Так есть ли какой-нибудь путь, который я могу попробовать? Заранее спасибо

ответ

0

Проблема заключается в том, что вы стилизации таблицу со следующими CSS:

.table-content- 
{ 
    position:fixed; 
    top:2.5em; 
    font-style: sans-serif; 
} 

DOMPDF не содержание страницы, которая фиксируется или абсолютное позиционируются. В настоящее время размещенное содержимое отображается следующим образом:

  • Абсолют: отображается на странице, на которой он оказывает только.
  • Исправлено: отображается на странице, на которой он отображается, и на любой следующей странице.

Удалите позиционирование на вашем столе, и оно должно выглядеть просто отлично.

Смежные вопросы