繁体   English   中英

如何从TCPDF中的Footer()方法检索当前页面的HTML代码?

[英]How to retrieve current page HTML code from Footer() method in TCPDF?

我正在使用TCPDF呈现一些通过一系列HTML表生成的报告。 这些表包含一些我想从Footer()方法解析并添加到当前页脚的跟踪代码。 任何想法如何从TCPDF获取当前页面的html代码?

我基本上是这样做的:

class SVNPDF extends TCPDF {

        // Page footer
        public function Footer() {

            // Position at 15 mm from bottom
            $this->SetY(-15);
            // Set font
            $this->SetFont('helvetica', 'I', 10);
            // Page number
            $this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'R', 0, '', 0, false, 'T', 'M');

            $this->SetY(-15);
            $this->SetFont('helvetica', 'I', 10);
            $this->Cell(0, 10, 'Picking #'.$glb_picking_num.'', 0, false, 'L', 0, '', 0, false, 'T', 'M');

            // HERE I NEED TO RETRIEVE CURRENT PAGE HTML CONTENT AND EXTRACT THE TRACKING NUMBER INSIDE FOR DISPLAY IN CURRENT FOOTER
        }
}

$report = 'SOME LONG HTML CODE HERE';
$pdf = new SVNPDF('L', 'mm', 'A4', true, 'UTF-8', false);
$pdf->AddPage();
$pdf->writeHTML($report, true, false, true, false, '');
$pdf->Output(dirname(__FILE__) . '/test.pdf', 'I');

我发现的唯一解决方案是使用标记定义我添加到上述SVNPDF类中的方法。 然后,TCPDF将使用tracking in参数调用此方法。

这是快照:

<tcpdf method="my_custom_func" params="'.TCPDF_STATIC::serializeTCPDFtagParameters(array('tracking number here')).'" />

并在SVNPDF类中:

public function my_custom_func( $tracking_num ){
            $cur_page = $this->PageNo();
            // I can now store the $tracking_num in some private array and retrieve it in the Footer() as per current page number
        }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM