2013-04-24 56 views

回答

1

簡單的藍莓!您可以使用頁面和框架來定義頁眉和頁腳,方法是將它們放入HTML文檔的樣式標記中。

<html> 
    <head> 
    <style> 
    /* Page margins are defined using CSS */ 
    @page { 
     margin: 1cm; 
     margin-top:2.5cm; 
     margin-bottom: 2.5cm; 

    /* Header frame starts within margin-top of @page */ 
     @frame header { 
     -pdf-frame-content: headerContent; /* headerContent is the #id of the element */ 
     top: 1cm; 
     margin-left: 1cm; 
     margin-right:1cm; 
     height:1cm; 
     } 

    /* Footer frame starts outside margin-bottom of @page */ 
     @frame footer { 
     -pdf-frame-content: footerContent; 
     bottom: 2cm; 
     margin-left: 1cm; 
     margin-right: 1cm; 
     height: 1cm; 
     } 
    } 
    </style> 
    </head> 
    <body> 
      <div id="headerContent">I'm a header!</div> 
      <p>I could be some content</p> 
      <div id="footerContent">I'm a footer! <pdf:pagenumber></div> 
    </body> 
</html> 

PDF:編號和副是用來顯示頁計數的標籤。還有更多的標籤包括在內。只需參考官方文檔!

來源HTML2PDF Github Documentation

4

看看這是什麼需要的朋友。頁眉和頁腳已修復並通知頁數。

<?php 
/** 
* HTML2PDF Librairy - example 
* 
* HTML => PDF convertor 
* distributed under the LGPL License 
* 
* @author  Laurent MINGUET <[email protected]> 
* 
* isset($_GET['vuehtml']) is not mandatory 
* it allow to display the result in the HTML format 
*/ 

ob_start(); 

// HTML template begin (no output) 

?> 
<style type="text/css"> 
<!-- 
    table.page_header {width: 100%; border: none; background-color: #DDDDFF; border-bottom: solid 1mm #AAAADD; padding: 2mm } 
    table.page_footer {width: 100%; border: none; background-color: #DDDDFF; border-top: solid 1mm #AAAADD; padding: 2mm} 

    div.niveau 
    { 
     padding-left: 5mm; 
    } 
--> 
</style> 
<page backtop="14mm" backbottom="14mm" backleft="10mm" backright="10mm" style="font-size: 12pt"> 
    <page_header> 
     <table class="page_header"> 
      <tr> 
       <td style="width: 100%; text-align: left;"> 
        Exemple d'utilisation des bookmarks 
       </td> 
      </tr> 
     </table> 
    </page_header> 
    <page_footer> 
     <table class="page_footer"> 
      <tr> 
       <td style="width: 100%; text-align: right"> 
        page [[page_cu]]/[[page_nb]] 
       </td> 
      </tr> 
     </table> 
    </page_footer> 
</page> 
<?php 

    // HTML end 
    // Getting the html which was not displayed into $content var 
    $content = ob_get_clean(); 

    require_once(dirname(__FILE__).'/../html2pdf.class.php'); 
    try 
    { 
     $html2pdf = new HTML2PDF('P', 'A4', 'fr', true, 'UTF-8', 0); 
     $html2pdf->writeHTML($content, isset($_GET['vuehtml'])); 
     $html2pdf->createIndex('Sommaire', 25, 12, false, true, 1); 
     $html2pdf->Output('bookmark.pdf'); 
    } 
    catch(HTML2PDF_exception $e) { 
     echo $e; 
     exit; 
    } 
相關問題