Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用FPDF';s WriteHTML()在页眉/页脚中_Php_Fpdf - Fatal编程技术网

Php 使用FPDF';s WriteHTML()在页眉/页脚中

Php 使用FPDF';s WriteHTML()在页眉/页脚中,php,fpdf,Php,Fpdf,我试图使用writeHTML脚本(此处:)以及教程6中的页眉和页脚(此处:) 我的代码如下所示: <?php require_once('WriteHTML.php'); class PDF extends FPDF { // Page footer function Footer() { $this->SetY(-30); $this->SetFont('Arial','I',8); $this->

我试图使用writeHTML脚本(此处:)以及教程6中的页眉和页脚(此处:)

我的代码如下所示:

<?php
require_once('WriteHTML.php');

class PDF extends FPDF
{
     // Page footer
     function Footer()
     {

     $this->SetY(-30);
     $this->SetFont('Arial','I',8);     
     $this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');
     $html = '<p>some HTML</p>';

     $this->WriteHTML($html);
     }

     // Some more functions... header, PrintChapter etc... 
}

$pdf = new PDF();
$pdf->SetTitle($title);
$pdf->AddPage();
$pdf->PrintChapter(1,'A RUNAWAY REEF','test.txt'); // print text file content
$pdf->Output();
?>

我得到以下错误:

在第15行的/path/to/test2.php中调用未定义的方法PDF::WriteHTML()


我缺少什么?

您需要扩展
PDF\u HTML
,而不是
FPDF
,因为
WriteHTML
PDF\u HTML
的一部分

如果希望继承工作,则始终需要扩展要使用的类。假设您想要扩展
PDF\u索引
,您仍然需要在继承的某处使用
WriteHTML

或许

PDF extends PDF_Index 

或者

但是你需要两者都在链条中才能让它工作

如果不将这两个函数都放在继承链中,则不会使用未使用的分支中的可用函数

       ---> PDF_HTML
     /
FPDF ----> PDF_Index ----> PDF

另外,PDF_HTML中的函数将不适用于有效的PDF

,但是我似乎无法理解继承链与更多脚本一起工作。添加书签和索引脚本,如果我将代码更新为
classpdf-extensedpdf\u-index
,例如,
WriteHTML($html)再次停止工作…感谢您的详细解释。工作起来很有魅力。我现在让每个脚本扩展上一个脚本,我希望我可以跟踪所有包含的脚本:)
PDF_HTML extends PDF_Index
       ---> PDF_HTML
     /
FPDF ----> PDF_Index ----> PDF