2017-05-13 73 views
1

我的代碼的HTML這樣的:如何在pdf中不顯示頁碼= 1? (HMTL CSS)

<!DOCTYPE html> 
<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 
     <title>Print PDF</title> 

     <style type="text/css"> 
      .footer { position: fixed; left: 0px; right: 0px; height: 50px;text-align: center; } 
      .footer .pagenum:before { content: counter(page); } 
     </style> 

    </head> 
    <body> 
     <h1>This is test</h1> 

     <table class="tg"> 
      <tr> 
       <th class="tg-3wr7">kolom 1</th> 
       <th class="tg-3wr7">kolom 2</th> 
       <th class="tg-3wr7">kolom 3</th> 
       <th class="tg-3wr7">kolom 4</th> 
       <th class="tg-3wr7">kolom 5</th> 
      </tr> 
      @php ($row = 22) 
      @for($i=0;$i<$row;$i++) 
      <tr> 
       <td class="tg-rv4w">test 1</td> 
       <td class="tg-rv4w">test 1</td> 
       <td class="tg-rv4w">test 1</td> 
       <td class="tg-rv4w">test 1</td> 
       <td class="tg-rv4w">test 1</td> 
      </tr> 
      @endfor 
     </table> 

     <div class="footer"> 
      <span class="pagenum"></span> 
     </div> 
    </body> 
</html> 

如果$行= 22,這將只顯示1頁是這樣的:

enter image description here

如果$行= 202,它會像這樣顯示7頁;

enter image description here

當存在多於1頁,第一頁不顯示頁碼。

但是,當只有1頁,第一頁顯示的頁碼

我要的是:

我要消失的頁面數量時,只有1頁

哪有我做它?

+0

讓我們看看你的鱈魚e出口到pdf –

回答

0

更新關於changes與DOMPDF的版本> = 0.7.0

  1. 因爲dompdf_config.inc.php文件已經從這個版本中刪除(而不再是引用)所有DOMPDF選項應該在運行時設置。

  2. FontMetrics類現在是實例化的,而不是靜態的。爲了簡化dompdf 早期版本中嵌入腳本的遷移,我們通過變量 $fontMetrics提供對實例化的FontMetrics類的訪問。請更新您的嵌入式腳本。對於 示例,FontMetrics::get_font('helvetica')現在將是 $fontMetrics->getFont('helvetica')

〜感謝Dennis Ameling's answer用於更新的信息。

查看dompdf_config.inc.php文件。事實證明,DOMPDF_ENABLE_PHP設置爲false,從而導致內聯php腳本被忽略。我簡單地編輯了dompdf_config.custom.inc.php以下內容,一切正常,並使用view中的後續代碼。

在DOMPDF/dompdf_config.custom.inc.php

<?php 
    define("DOMPDF_ENABLE_PHP", true); 

在運行時

$dompdf->set_option("isPhpEnabled", true); 

然後,在我的HTML文件

<body> 
    <script type="text/php"> 
     if (isset($pdf)) { 
      // OLD 
      // $font = Font_Metrics::get_font("helvetica", "bold"); 
      // $pdf->page_text(72, 18, "{PAGE_NUM} of {PAGE_COUNT}", $font, 6, array(255,0,0)); 
      // v.0.7.0 and greater 
      $x = 72; 
      $y = 18; 
      $text = "{PAGE_NUM} of {PAGE_COUNT}"; 
      $font = $fontMetrics->get_font("helvetica", "bold"); 
      $size = 6; 
      $color = array(255,0,0); 
      $word_space = 0.0; // default 
      $char_space = 0.0; // default 
      $angle = 0.0; // default 
      $pdf->page_text($x, $y, $text, $font, $size, $color, $word_space, $char_space, $angle); 
     } 
    </script> 
    <div> 

如果你走這條路線,別忘了重啓Apache