2015-09-26 71 views
2

我想在CodeIgniter中使用DOMPDF工具生成PDF。生成帶有無邊距背景圖像的PDF

我有一個形象,我想在後臺完整的DIN A4 PDF頁面來顯示它,當我嘗試這樣做:

body{ 
    background-image: url('http://blogs.ucl.ac.uk/quantum/files/2013/12/artwork-fullsize.jpg'); background-position: bottom right; background-repeat: no-repeat; 
    background-size: 100%; 
    width:100%; 
    height:100%; 
    padding: 0px; 
    margin: 0px; 
} 

我有一個PDF,但它似乎保證金(或填充) 。我想要沒有邊距或填充,只有完整的100%圖像背景。

謝謝,

回答

2

很久以前,我也偶然發現了你的問題。這是我所做的,使頁面沒有利潤。

<style>@page{margin:0}</style> 
2

dompdf尚不支持background-size聲明。最簡單的解決方法是絕對放置圖像並將尺寸設置爲頁面的尺寸(百分比計算仍然顯得有點偏離)。你必須考慮頁邊距,所以你應該設置這些。

<!DOCTYPE html> 
<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 
    <style> 
    @page { margin: .5in; } 
    .bg { top: -.5in; right: -.5in; bottom: -.5in; left: -.5in; position: absolute; z-index: -1000; min-width: 8.5in; min-height: 11in; } 
    </style> 
</head> 
<body> 
    <img class="bg" src="http://eclecticgeek.com/images/macro/ants.jpg"> 
</body> 
</html> 
+0

It works @BrianS thanks =) –