dompdf - 在第一页之后设置页面边距

3

我正在使用 dompdfHTML 转换为 pdf 文件,目前它已经可以正常工作。但问题是我需要在所有页面上都有页边距,除了第一页。第一页应该有一张覆盖整个页面的图片。但现在所有页面都有页边距。

我无法禁用第一页的页边距。非常感谢任何帮助。提前致谢。

以下是我的 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>
1个回答

5
请试试这个:

    @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; }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接