Php 如何在html2pdf中的每个页面上放置列标题

Php 如何在html2pdf中的每个页面上放置列标题,php,html,html2pdf,Php,Html,Html2pdf,我正在使用html2pdf类从html页面生成pdf文件。我想在每个页面上放置列标题。但我不知道该怎么做。这是我的密码: <?php function linewrap($string, $width, $break, $cut) { $array = explode("\n", $string); $string = ""; foreach($array as $key => $val) { $string .= wordwrap($val, $width, $break, $

我正在使用html2pdf类从html页面生成pdf文件。我想在每个页面上放置列标题。但我不知道该怎么做。这是我的密码:

<?php 
function linewrap($string, $width, $break, $cut) {
$array = explode("\n", $string);
$string = "";
foreach($array as $key => $val) {
 $string .= wordwrap($val, $width, $break, $cut);
 $string .= "\n";
}
return $string;
}
if(isset($_POST['download'])){
//connect to the database
require_once('../../connect.php'); 
$status=$_POST['status'];

//retrieve the specific rows by given status
$query="SELECT *
        FROM `incident_status`
        WHERE status='".$status."'";

//execute the query
$run=mysql_query($query);
$i=1;

//content to be downloaded
  $content='<page backtop="2mm" backbottom="2mm" backleft="2mm" backright="2mm" style="font-size:6pt;bordercolor:#000000;">';
  $content .='<p style="text-align:center;"><b>Incident Status Report</b> of the Pending cases </p>';
  $content.='<table align="center" style="background-color: #DDDDFF; border-bottom: solid 1mm #AAAADD; padding: 2mm " border="1">';
  $content.='<tr>
                <th>SL:</th>
                <th>Date:</th>
                <th>Case No:</th>
                <th>Customer Name:</th>
                <th>Cell No:</th>
                <th>Agent id:</th>
                <th>Card no:</th>
                <th>Problem Type:</th>
                <th>Remarks:</th>
                <th>Open By:</th>
            </tr>';
    while($data=mysql_fetch_array($run)){
        $date=$data['date'];
        $case_no=$data['case_no'];
        $name=$data['name'];
        $cell_no=$data['cell_no'];
        $agent_id=$data['agent_id'];
        $card_no=$data['card_no'];
        $problem_type=$data['problem_type'];
        $open_by=$data['open_by'];
        $close_by=$data['close_by'];
        $content.='<tr style="border: solid 1mm #000000;">';
        $content.='<td>'.$i++.'</td>';
        $content.='<td>'.$date.'</td>';
        $content.='<td>'.$case_no.'</td>';
        $content.='<td>'.$name.'</td>';
        $content.='<td>'.$cell_no.'</td>';
        $content.='<td>'.$agent_id.'</td>';
        $content.='<td>'.$card_no.'</td>';
        $content.='<td>'.$problem_type.'</td>';
        $content.='<td>';
        $content.='<ol>';
        $remarks = explode(";", $data['remarks']);
         foreach($remarks as $remark){
           $wrap=linewrap($remark,50,"<br/>",true);
           $content.='<li>'.$wrap.'</li>';  
          }
        $content.='</ol>';
        $content.='</td>';
        $content.='<td>'.$open_by.'</td>';
        $content.='</tr>';
    }
                $content.='</table></page>';
//end of content

//get the html2pdf class
require_once(dirname(__FILE__).'/html2pdf/html2pdf.class.php');

//new object of html2pdf class
$html2pdf = new HTML2PDF('P','','fr');
$html2pdf->WriteHTML($content);
$html2pdf->Output('incident_status_report_of_pending_cases.pdf');
}
?>

请把这件事告诉我。我非常需要这个帮助,因为这是我的最后一个项目,我只是在这一事实上感到受挫。请提前感谢。

尝试在您的phtml页面中添加以下内容:

<page>
   <page_header>
      <table class="page_header">
         <tr>
            <td style="width: 50%; text-align: left">
               title1
            </td>
            <td style="width: 50%; text-align: right">
               title2
            </td>
         </tr>
      </table>
   </page_header>

   <div class="note">
      Your content
   </div>
</page>
有关更多参考,请查看此:about.pdf示例


希望这有帮助

尝试在您的phtml页面中添加以下内容:

<page>
   <page_header>
      <table class="page_header">
         <tr>
            <td style="width: 50%; text-align: left">
               title1
            </td>
            <td style="width: 50%; text-align: right">
               title2
            </td>
         </tr>
      </table>
   </page_header>

   <div class="note">
      Your content
   </div>
</page>
有关更多参考,请查看此:about.pdf示例

希望这有帮助

我找到了答案:

  $content.='<thead style="display:table-header-group;">
                <tr>
                    <th>SL:</th>
                    <th>Date:</th>
                    <th>Case No:</th>
                    <th>Customer Name:</th>
                    <th>Cell No:</th>
                    <th>Agent id:</th>
                    <th>Card no:</th>
                    <th>Problem Type:</th>
                    <th>Remarks:</th>
                    <th>Open By:</th>
                </tr>
            </thead>';
此标记将表格标题打印到每页。谢谢。

我找到了答案:

  $content.='<thead style="display:table-header-group;">
                <tr>
                    <th>SL:</th>
                    <th>Date:</th>
                    <th>Case No:</th>
                    <th>Customer Name:</th>
                    <th>Cell No:</th>
                    <th>Agent id:</th>
                    <th>Card no:</th>
                    <th>Problem Type:</th>
                    <th>Remarks:</th>
                    <th>Open By:</th>
                </tr>
            </thead>';

此标记将表格标题打印到每页。谢谢。

谢谢……但我还有一个问题……这就是我如何定义类页面的css样式\u页眉/注释。我在同一页面中定义了css规则,但它显示了错误。那么如何定义。。。。再次感谢:欢迎。接受并投票给我。这将对未来的用户有用。谢谢……但我还有一个疑问……这就是我如何定义类页面的css样式。\u页眉/注释。我在同一页面中定义了css规则,但它显示了我的错误。那么如何定义。。。。再次感谢:欢迎。接受并投票给我。这将对未来的用户有用。