如何在dompdf 6.0 beta 2中做一个页脚?

Zac*_*ner 0 css dompdf

在最近的dompdf版本(domdpf beta 2)中,出于安全原因,内联php被禁用.这反过来导致了之前的页脚/标题代码:

<script type="text/php">

if ( isset($pdf) ) {

  $font = Font_Metrics::get_font("helvetica", "bold");
  $pdf->page_text(72, 18, "Header: {PAGE_NUM} of {PAGE_COUNT}", $font, 6, array(0,0,0));

}
</script>
Run Code Online (Sandbox Code Playgroud)

不再工作了.

我现在正在尝试使用CSS重新创建此脚本所执行的操作.到目前为止,我已经弄清楚如何让CSS计算页面:

.pagenum:before { content: counter(page); }
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是将页脚粘贴到页面底部.关于如何执行此操作的大多数CSS教程似乎都不起作用.这是我的页面的CSS:

html,body {
     font-family:interstate;
    height:100%;
    width:100%;
    overflow:auto;
    margin-left: 40px;
    margin-right: 40px;
    margin-top: 20px;   
 margin-bottom:40px;
 min-height: 100%;
}



P.breakhere {page-break-before: always}

table
{
  border-collapse: collapse;
    page-break-inside: avoid;
  font-size:15px;

    }

td
{
border: 1px solid #000

}
.noBorder {
    border: 0
}


#header {background:#ffffff url('gradient.png') no-repeat center center;
height: 100px;

}

#text {
position:relative;
text-align:center;
padding:10px;
}



.pagenum:before { content: counter(page); }
Run Code Online (Sandbox Code Playgroud)

我的希望是有人可以提供适当的#footer位,所以我的页脚文本将正确地粘贴在页面底部.

谢谢!!

Bri*_*anS 12

内嵌脚本默认是禁用的,但如果你觉得你不容易受到任何安全问题,通过设置您可以安全地重新启用它DOMPDF_ENABLE_PHPtrue.

要使用HTML + CSS创建页眉/页脚,您将使用固定位置元素.

CSS

#footer {
  position: fixed;
  bottom: 0px;
  left: 0px;
  right: 0px;
  height: 100px;
  text-align: center;
  background-color: lightgray;
  border-top: 2px solid gray;
}
.pagenum:before {
  content: counter(page);
}
Run Code Online (Sandbox Code Playgroud)

HTML

<div id="footer">
  <p>page <span class="pagenum"></span></p>
</div>
Run Code Online (Sandbox Code Playgroud)

HTML + CSS方法的主要缺点是目前无法使用此方法获取总页数.