2016-12-21 5 views
2

여기에서 얻을 : https://github.com/barryvdh/laravel-dompdflaravel dompdf의 모든 페이지에 페이지 번호를 추가하는 방법은 무엇입니까?

내 컨트롤러는 다음과 같이이다 :

public function listdata() 
{ 
    $pdf=PDF::loadView('print_tests.test_pdf'); 
    $pdf->setPaper('L', 'landscape'); 
    return $pdf->stream('test_pdf.pdf'); 
} 

내보기는 다음과 같이이다 :

나는 모든 페이지를 원하는
<table> 
    <tr> 
     <th>header1</th> 
     <th>header2</th> 
     <th>header3</th> 
    </tr> 
    <tr> 
     <td>content-row-1</td> 
     <td>content-row-1</td> 
     <td>content-row-1</td> 
    </tr> 
    <tr> 
     <td>content-row-2</td> 
     <td>content-row-2</td> 
     <td>content-row-2</td> 
    </tr> 
</table> 

는 페이지 번호

있다

나를 도울 수있는 사람이 있습니까?

+0

너 봤어? 수락 된 답변은 여기에서 찾을 수 있습니다. http://stackoverflow.com/questions/19983610/how-to-get-page-number-on-dompdf-pdf-when-using-view –

답변

2

이하의 절차 그것을 달성하기 위해 :
이 - /config/dompdf.php
에서 DOMPDF_ENABLE_PHP 사용 - php artisan vendor:publish command
를 통해 공급 업체에 파일을 게시 - 컨트롤러에서 $pdf 객체를 전달합니다
- 뷰 파일 내부 코드 아래에 추가 :

<script type="text/php"> 
    if (isset($pdf)) { 
     $font = Font_Metrics::get_font("helvetica", "bold"); 
     $pdf->page_text(72, 18, "Header: {PAGE_NUM} of {PAGE_COUNT}", $font, 6, array(0,0,0)); 
    } 
</script> 

더 많은 아이디어를 얻을 수 있습니다. Page count and page number

+0

버전이 0.7 이상인 경우 [Dennis Ameling 's solution ] (https://stackoverflow.com/a/38788676/5727643). –