编辑:
我尝试使用“Code128条形码”(来自此页面fpdf.org (fpdf.org->scripts->Code128 barcode)中的一个类)。
方法Code128()位于"code128.php“中的”PDF_Code128扩展FPDF“类中。
当我调用类PDF_Code128()的方法Code128时,出现了这个错误“调用未定义的方法FPDF::Code128()”。
这是一个例子
<?php
require('fpdf.php');
require('code128.php');
$pdf = new FPDF();
$pdf->AddPage();
$code='ABCDEFG1234567890AbCdEf';
$pdf->Code128(50,170,$code,125,20);//<--Call to undefined method FPDF::Code128()
$pdf->SetFont('Helvetica','',10);
$pdf->SetXY(33,239);
$pdf->Write(1,'Some text');
$pdf->Output();
?>如果条形码对象是使用$pdf = new PDF_Code128()创建的;条形码正在工作,并且$pdf对象可以访问父方法,如SetXY()和Write(),但是如果使用$pdf = new FPDF()创建,父对象就不能使用像Code128()这样的子方法?
下面是我想要的一个例子:
$obj = new PDF_Code128();
$code='0123456789';
$obj->Code128(45,280,$code,125,10);
$pdf = new FPDF();
$pdf->AddPage();
--here I want to add $obj to $pdf, or just call Code128() without creating $obj if possible--
--kind of obj1->addChild(obj2)---
$pdf->Output(); 有什么建议吗?
发布于 2014-04-30 22:35:04
(感谢你的努力和帮助,h2ooooooo!感谢stackoverflow.com,在这里我找到了我的大多数问题已经回答和准备好的解决方案:
在文件rotation.php中,PDF_Rotate类扩展了PDF_Code128 (而不是扩展了!)
Child2(类轮换)>extends>Child1(类code128)>extends>Parent(类FPDF)
创建Child2时,可以使用父方法(Child1和Parent)。仅此而已,我的问题可能不是很清楚。
下面是结合使用FPDF、Code128和Rotation类的最终代码:
<?php
require('fpdf.php');
require('code128.php');//<--This must be called before rotation.php (because rotation extends code128 class)
require('rotation.php');
class PDF extends PDF_Rotate
{
function RotatedText($x,$y,$txt,$angle)
{
//Text rotated around its origin
$this->Rotate($angle,$x,$y);
$this->Text($x,$y,$txt);
$this->Rotate(0);
}
}
$pdf = new PDF();
$pdf->AddPage();
$pdf->SetFont('Helvetica','B',10);
$code='0123456789';
$pdf->Code128(13,15,$code,125,10);
$pdf->RotatedText(10,30,'Vertical Text',90);
$pdf->Write(1,'text test');
$pdf->Output();
?>https://stackoverflow.com/questions/23226796
复制相似问题