php – 在TCPDF中,如何将当前页码作为整数?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – 在TCPDF中,如何将当前页码作为整数?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4311字,纯文字阅读大概需要7分钟。
内容图文
![php – 在TCPDF中,如何将当前页码作为整数?](/upload/InfoBanner/zyjiaocheng/809/203aea628fb64d048e592af549dacaed.jpg)
我尝试使用$pdf-getAliasNumPage(),如果它以PDF格式呈现,它会显示页码.
但是当我在基本PHP上进行实验并打印它时,它只返回“{:pnp:}”.
如果页面已经更改,我曾经有一个if条件,这样我可以重新设置一个值= 0,但由于getAliasNumPage()的返回值等于“{:pnp:}”,条件总是为false.
有什么办法可以将页码作为整数找到吗? 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 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 .= ' </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()
http://www.tcpdf.org/doc/code/classTCPDF.html#a9ad828b184f08828f570a7e52316ba79
TCPDF::PageNo()
Returns the current page number.
Returns
int page number
编辑.
好的,现在(我认为)我明白你想做什么,你只添加1页并使用自动分页符,你也不想自动为页脚中的页面编号.在这种情况下,您应该使用getAliasNumPage()和getAliasNbPages().定义以下变量(按照您的意愿编辑文本):
$PgNo= "This is the page " . $pdf->getAliasNumPage() . " of " . $pdf->getAliasNbPages();
把它放在php文件的任何地方(在定义字体之后放置它很重要)然后只需使用变量$PgNo(或者你可以调用它),无论你需要什么.您只需要定义一次,稍后它将自动获取值,具体取决于它所在的pdf文档中的哪个页面.
内容总结
以上是互联网集市为您收集整理的php – 在TCPDF中,如何将当前页码作为整数?全部内容,希望文章能够帮你解决php – 在TCPDF中,如何将当前页码作为整数?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。