2016-03-03 78 views
3

我正在使用dompdfHTML转换为pdf文件。它工作正常。但问题是我需要为页面页边距的所有页面第一页。第一页应该有一个覆盖整个页面的图像。但现在所有页面都包含第一个页面。dompdf - 仅在第一页后设置页边距

我无法为第一页禁用页边距。任何帮助是极大的赞赏。提前致谢。

下面是我的CSS

<style type="text/css"> 
    body { margin: 0px; } 
    @page { margin: 50px; } 
    #header { 
     position: fixed; 
     left: 0px; 
     top: -52px; 
     height: 50px; 
     border-bottom: 2px solid #797979; 
     margin: 0; 
    } 
    #footer { 
     position: fixed; 
     left: 0px; 
     bottom: -52px; 
     height: 50px; 
     border-top: 2px solid #797979; 
     margin: 0; 
    } 
    #footer .page:after { content: counter(page); } 
    .firstpage { 
     position: absolute; 
     page-break-after: always; 
     top: -50px; 
     width: 100%; 
     margin: 0; 
    } 
    .otherpages{ margin: 0; } 
    </style> 

这是我的HTML

<div class="firstpage"> 
    <img src="pdf-bg.jpg" style="width:100%; height:auto;/> 
    </div> 

    <div id="header"> 
    <p><?php echo date("F j, Y"); ?></p> 
    </div> 

    <div id="footer"> 
    <p class="page">Page <?php $PAGE_NUM ?></p> 
    </div>  

    <div class="otherpages"> 
     some content 
    </div> 

回答

3

试试这个,

@page { margin: 50px 0; } 
    .firstpage { 
     position: absolute; 
     page-break-after: always; 
     top: -50px; // compensating for @page top margin 
     width: 100%; 
     margin: 0; 
    } 
    .otherpages{ margin: 0 50px; }