2016-10-04 31 views
1

我知道有類似的問題,但其中沒有解決我的問題。我想MPDF做的是以下幾點: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 
... 

下面的代碼的方式延伸的形象,我想實現:

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>'); 

... 
相關問題