2016-10-04 4 views
1

비슷한 질문이 있지만 그 중 누구도 내 문제를 해결하지 못한다는 것을 알고 있습니다.MPdf - 전체 페이지 크기 이미지, 단 한 페이지에만 해당

Page 1: Text for item 1 
Page 2: Full width and height image to cover the page with an image of item 1 
Page 3: Text for item 2 
Page 4: Full width and height image to cover the page with an image of item 2 
... 

다음 코드는 방법으로 이미지를 뻗어, 내가 달성하고자 : 내가 뭘 mPDF 함께하고 싶은 기능은 다음이다

body { 
     background-image:url("image1.jpg"); 
     background-image-resize: 5; 
     background-position: top center; 
    } 

을하지만이 모든 페이지에 이미지를 설정하는 결과 (나는 그것의 신체 요소를 안다).

<div style=' 
     position: absolute; 
     top: 0; 
     left: 0; 
     width: 100%; 
     height: 100%; 
     background-image:url("image1.jpg"); 
     background-image-resize: 5; 
     background-position: top center; 
    '></div> 

을하지만 그건 작동하지 않습니다 : 그래서 나는 다음 시도했다. 그래서 나는 색깔 대신에 이미지와 같은 코드를 시도했다 :

<div style=' 
     position: absolute; 
     top: 0; 
     left: 0; 
     width: 100%; 
     height: 100%; 
     background: #F00; 
     '> 
    </div> 
    <div style="page-break-before: always;"></div> 

그리고 이것은 작동 중이다. 전체 페이지가 빨간색입니다. 그렇다면 어떻게 이미지를 그대로 유지할 수 있을까요?

아이디어가 있으십니까?

답변

3

많은 시험을 거친 후, 이렇게하는 쉬운 방법은 HTML 코드를 별도의 부분으로 나누어 별도의 WriteHtml 호출로 삽입하는 것입니다. 예 :

// Create object 
$mpdf = new \mPDF('utf-8'); 

// Create first text page 
$mpdf->WriteHTML('<p>Text for item 1</p>'); 

// Add a new page with the image 
$mpdf->AddPage(); 
$mpdf->WriteHTML("<html><body style='background-image:url(\"image1.jpg\"); background-image-resize: 5; background-position: top center;'></body></html>"); 


// Create second page 
$mpdf->AddPage(); 
$mpdf->WriteHTML('<p>Text for item 1</p>'); 

...