php - 在 TCPDF 中,如何将当前页码获取为整数?

标签 php pdf tcpdf

我尝试使用 $pdf-getAliasNumPage() ,如果以 PDF 格式呈现,它会显示页码。

但是当我在一个基本的 PHP 上进行试验并打印它时,它只返回“{:pnp:}”。

如果页面已经更改,我曾经有一个 if 条件,以便我可以再次重置值 = 0,但由于 getAliasNumPage() 的返回值等于 "{:pnp: }".

有什么方法可以找到整数形式的页码吗?那是什么 TCPDF 功能?

我只声明了一次 AddPage(),因为我不需要它。

已经使用了$pdf->getPage();只返回 0。

谢谢!

$this->payroll_id  = $request->getParameter('payroll_id');
$this->class = new PsPayroll();
$config = sfTCPDFPluginConfigHandler::loadConfig();
$pdf = new reportPDF(LANDSCAPE, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); 

$month = $this->class->mlFetchPayroll();
$month->execute(array($this->payroll_id));
$catch = "";
while ($print_month = $month->fetch()){
  $catch = $print_month[8];
}

$pdf->SetCreator(Aaron);
$pdf->setMonth($catch);
$pdf->SetAuthor('');
$pdf->SetTitle('Payroll Report');
$pdf->SetSubject('');
$pdf->SetKeywords('');

$pdf->SetHeaderData('logo.png', '25', '', $catch);

$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP + 4, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER + 15);

$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

$pdf->setFontSubsetting(true);

$pdf->SetFont('freesans', '', 9.5, '', true);  
$html .= '<table class = "table hover">
    <thead>
      <tr>
        <th>Employee Information</th>
        <th>Monthly Salary</th>
        <th>Earnings</th>
        <th>Deductions</th>
        <th>Net Pay &nbsp;&nbsp;&nbsp;&nbsp; Signature</th>
      </tr>
    </thead>
    <tbody>';

$pager = 1; 
$prepare = $this->class->mlFetchPayroll();
$prepare->execute(array($this->payroll_id));
    while ($myrow = $prepare->fetch()){
      $total_net_pay = 0;
      $total_earning = 0;
      $total_deduction = 0;
      $html .= '<br><tr nobr="true"><td>' . $myrow[2] . '<br>'. $myrow[3] . '<br>' . $myrow[4] . '</td><td>' . number_format($myrow[5], 2) . '</td><td>';

        $earning_array = $this->class->mlFetchEarningPayslip($myrow[10]);
        foreach ($earning_array as $k => $valk){
        $net_pay += $valk;
        $total_earning += $valk;
            $html .=  '<table><tr><td>' .  $k  . '</td><td>' .  number_format($valk, 2) . '</td></tr></table>';
        }

        $html .= "</td><td>";
        $deduction_array = $this->class->mlFetchDeductionPayslip($myrow[10]);
        foreach ($deduction_array as $i => $val){
        $net_pay -= $val;
        $total_deduction += $val;
        $html .= '<table><tr><td>' .  $i . '</td><td>'.  number_format($val, 2) . '</td></tr></table>';

      }

      $html .= '</td><td>';

        $array_date = $this->class->mlDivideMonth($myrow[8]);
        $k = 0;
        foreach ($array_date as $value){
          $breakdown = 0.00;
          $k++;
          $monthly_salary = $myrow[5]; 

          $monthly_salary += $total_earning - $this->class->mlFetchPERA($myrow[10]);
          $monthly_salary -= $total_deduction;

          $break_down = $monthly_salary/ 4;

          $html .= '<table><tr><td align="right">'; 
            if ($breakdown < 0) 
              $html .=  0;
            else if   ($k == 2){
              $a = round($break_down, 2);
              $b = $a + $this->class->mlFetchPERA($myrow[10]);
              $c = number_format($b, 2);
              $html .= $c;
            }
            else{
              $a = round($break_down, 2);
              $b = number_format($a, 2);
              $html .= $b;
            }

            $html .= '&nbsp;&nbsp;&nbsp;</td><td>............... </td><td>' .  $value .  '</td></tr></table>';
      }
      $html .= '</td></tr>';

      $pager = $pdf->getAliasNumPage();

      if ($pager == 1){
        $html .= 'This is first page ' . $pdf->getAliasNumPage();
      }
      else{
        $pager = $pdf->getAliasNumPage();
        $html .= "This is page " . $pdf->getAliasNumPage();
      }

     // $html .= 'sample '. $pager;
}
$html .= '</tbody></table>';   

$pdf->AddPage();  
$pdf->writeHTML($html, true, false, false, true, 'Aaron');

$pdf->Output('payroll_'.$catch.'.pdf', 'I');

throw new sfStopException();

最佳答案

PageNo()getPage() 都会返回当前页码。

$this->PageNo();

$this->getPage();

关于php - 在 TCPDF 中,如何将当前页码获取为整数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29787283/

相关文章:

php - 如何使用 mySQL/PHP 显示数据库中的结构化信息?

python - 将 PDF 转换为文本 - 保留表格行 - Python

PHP TCPDF 打印表不工作

php - "Push"循环中关联数组末尾的对象

php - 如何在 PHP 中将 Javascript 字符串编码为 Unicode 并解码为 utf-8?

php - 在 PHP 的类内部使用时,traits 中的静态变量如何不失去其值(value)?

php - tcpdf 编码汉字

java - 使用自定义属性从 PDF 添加/删除/检索信息

java - 从 Java 应用程序即时打开 PDF 文件

TCPDF - 仅在某些页面上有页脚/页眉