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

标签 php html css dompdf

我正在使用 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>

最佳答案

试试这个,

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

关于php - dompdf - 仅在第一页之后设置页边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35763845/

相关文章:

php - 什么会导致网站不总是加载

Android HTML 按钮 onclick 事件

html - CSS 过滤器不能很好地跨浏览器工作

javascript - 通过div模糊页面背景?

magento - 将 magento 购物车 block 加载到下拉面板

php - 将 php 页面的执行限制为来自某个 ip 范围的请求

javascript - Facebook - 获取带有/不带有访问 token 的页面 ID

php - 使用 Thrift 生成的文件中的 PSR-4 命名空间

html - 如何从右侧缩进文本?

html - 为什么我的按钮的位置会影响我的列表的位置?