As in the title, I am having problems combining the two classes. Although this is about FPDF, I think this is a regular question, since the question could be about any script.
I use FPDF to create PDFs on the fly. I use it in conjunction with the FPDI class to add vector images to a PDF file. The script can be found below and works like a charm.
<?php
require_once('../fpdf16/fpdf.php');
require_once('../fpdi131/fpdi.php');
require('code128.php');
class bezwaar extends FPDI
{
function Header()
{
global $tplidx;
global $pagecount;
$this->SetFont('Arial','',8);
if($this->PageNo()>1) $this->SetY(62);
$pagecount = $this->setSourceFile('standaardbezwaar.pdf');
$tplidx = $this->importPage(1, '/MediaBox');
$this->useTemplate($tplidx, 0, 0, 210);
}
}
$pdf = new bezwaar();
$pdf->AliasNbPages();
$pdf->SetTopMargin(34.7);
$pdf->addPage();
$pdf->SetFont('Arial','',8);
$pdf->MultiCell(0,4,$inhoud);
$pdf->Output();
?>
The problem is that I would like to add another class to add barcodes, but I do not know how to integrate it. The script below works fine with FPDF, but not with combined FPDI.
<?php
$pdf=new PDF_Code128();
$code='CODE 128';
$pdf->Code128(50,20,$code,80,20);
$pdf->SetXY(50,45);
$pdf->Write(5,'A set: "'.$code.'"');
?>
The problem is probably that I need to combine these two:
<?php
class bezwaar extends FPDI { }
class PDF_Code128 extends FPDF { }
$pdf = new PDF_Code128();
$pdf = new bezwaar();
?>
Sources
FPDF: http:
FPDI: http:
Barcodeclass: http:
Question
- , ()? PHP, , . enter code here
, , ,
require_once('../fpdf16/fpdf.php');
require_once('../fpdi131/fpdi.php');
require('code128.php');
class bezwaar extends FPDI // for example
{
function Header()
{
global $tplidx;
global $pagecount;
$this->SetFont('Arial','',8);
if($this->PageNo()>1) $this->SetY(62);
$pagecount = $this->setSourceFile('standaardbezwaar.pdf');
$tplidx = $this->importPage(1, '/MediaBox');
$this->useTemplate($tplidx, 0, 0, 210);
}
protected $_pdf;
protected $_code = 'CODE 128';
public function __construct(PDF_Code128 $pdf)
{
$this->_pdf = $pdf;
parent::__construct();
}
public function setCode($code)
{
$this->_code = $code;
return $this;
}
public function getCode()
{
return $this->_code;
}
public function setPdfStuff()
{
$this->_pdf->Code128(50, 20, $this->_code, 80, 20);
$this->_pdf->SetXY(50, 45);
$this->_pdf->Write(5,'A set: "'.$this->_code.'"');
}
}
$pdf = new bezwaar(new PDF_Code128());
$pdf->AliasNbPages();
$pdf->SetTopMargin(34.7);
$pdf->addPage();
$pdf->SetFont('Arial','',8);
$pdf->MultiCell(0,4,$inhoud);
$pdf->setPdfStuff();
$pdf->Output();
: /home/fpdf 16/fpdf.php 812
, , . - FPDI. script , : $pdf- > Code128 (50,20, $code, 80,20), -. - , ?
require_once('../fpdf16/fpdf.php');
require_once('../fpdi131/fpdi.php');
require('code128.php');
class bezwaar extends FPDI
{
function Header()
{
global $tplidx;
global $pagecount;
$this->SetFont('Arial','',8);
if($this->PageNo()>1) $this->SetY(62);
$pagecount = $this->setSourceFile('standaardbezwaar.pdf');
$tplidx = $this->importPage(1, '/MediaBox');
$this->useTemplate($tplidx, 0, 0, 210);
}
var $T128;
var $ABCset="";
var $Aset="";
var $Bset="";
var $Cset="";
var $SetFrom;
var $SetTo;
var $JStart = array("A"=>103, "B"=>104, "C"=>105);
var $JSwap = array("A"=>101, "B"=>100, "C"=>99);
function PDF_Code128($orientation='P', $unit='mm', $format='A4') {
parent::FPDF($orientation,$unit,$format);
$this->T128[] = array(2, 1, 2, 2, 2, 2);
$this->T128[] = array(2, 2, 2, 1, 2, 2);
$this->T128[] = array(2, 2, 2, 2, 2, 1);
$this->T128[] = array(1, 2, 1, 2, 2, 3);
$this->T128[] = array(1, 2, 1, 3, 2, 2);
$this->T128[] = array(1, 3, 1, 2, 2, 2);
$this->T128[] = array(1, 2, 2, 2, 1, 3);
$this->T128[] = array(1, 2, 2, 3, 1, 2);
$this->T128[] = array(1, 3, 2, 2, 1, 2);
$this->T128[] = array(2, 2, 1, 2, 1, 3);
$this->T128[] = array(2, 2, 1, 3, 1, 2);
$this->T128[] = array(2, 3, 1, 2, 1, 2);
$this->T128[] = array(1, 1, 2, 2, 3, 2);
$this->T128[] = array(1, 2, 2, 1, 3, 2);
$this->T128[] = array(1, 2, 2, 2, 3, 1);
$this->T128[] = array(1, 1, 3, 2, 2, 2);
$this->T128[] = array(1, 2, 3, 1, 2, 2);
$this->T128[] = array(1, 2, 3, 2, 2, 1);
$this->T128[] = array(2, 2, 3, 2, 1, 1);
$this->T128[] = array(2, 2, 1, 1, 3, 2);
$this->T128[] = array(2, 2, 1, 2, 3, 1);
$this->T128[] = array(2, 1, 3, 2, 1, 2);
$this->T128[] = array(2, 2, 3, 1, 1, 2);
$this->T128[] = array(3, 1, 2, 1, 3, 1);
$this->T128[] = array(3, 1, 1, 2, 2, 2);
$this->T128[] = array(3, 2, 1, 1, 2, 2);
$this->T128[] = array(3, 2, 1, 2, 2, 1);
$this->T128[] = array(3, 1, 2, 2, 1, 2);
$this->T128[] = array(3, 2, 2, 1, 1, 2);
$this->T128[] = array(3, 2, 2, 2, 1, 1);
$this->T128[] = array(2, 1, 2, 1, 2, 3);
$this->T128[] = array(2, 1, 2, 3, 2, 1);
$this->T128[] = array(2, 3, 2, 1, 2, 1);
$this->T128[] = array(1, 1, 1, 3, 2, 3);
$this->T128[] = array(1, 3, 1, 1, 2, 3);
$this->T128[] = array(1, 3, 1, 3, 2, 1);
$this->T128[] = array(1, 1, 2, 3, 1, 3);
$this->T128[] = array(1, 3, 2, 1, 1, 3);
$this->T128[] = array(1, 3, 2, 3, 1, 1);
$this->T128[] = array(2, 1, 1, 3, 1, 3);
$this->T128[] = array(2, 3, 1, 1, 1, 3);
$this->T128[] = array(2, 3, 1, 3, 1, 1);
$this->T128[] = array(1, 1, 2, 1, 3, 3);
$this->T128[] = array(1, 1, 2, 3, 3, 1);
$this->T128[] = array(1, 3, 2, 1, 3, 1);
$this->T128[] = array(1, 1, 3, 1, 2, 3);
$this->T128[] = array(1, 1, 3, 3, 2, 1);
$this->T128[] = array(1, 3, 3, 1, 2, 1);
$this->T128[] = array(3, 1, 3, 1, 2, 1);
$this->T128[] = array(2, 1, 1, 3, 3, 1);
$this->T128[] = array(2, 3, 1, 1, 3, 1);
$this->T128[] = array(2, 1, 3, 1, 1, 3);
$this->T128[] = array(2, 1, 3, 3, 1, 1);
$this->T128[] = array(2, 1, 3, 1, 3, 1);
$this->T128[] = array(3, 1, 1, 1, 2, 3);
$this->T128[] = array(3, 1, 1, 3, 2, 1);
$this->T128[] = array(3, 3, 1, 1, 2, 1);
$this->T128[] = array(3, 1, 2, 1, 1, 3);
$this->T128[] = array(3, 1, 2, 3, 1, 1);
$this->T128[] = array(3, 3, 2, 1, 1, 1);
$this->T128[] = array(3, 1, 4, 1, 1, 1);
$this->T128[] = array(2, 2, 1, 4, 1, 1);
$this->T128[] = array(4, 3, 1, 1, 1, 1);
$this->T128[] = array(1, 1, 1, 2, 2, 4);
$this->T128[] = array(1, 1, 1, 4, 2, 2);
$this->T128[] = array(1, 2, 1, 1, 2, 4);
$this->T128[] = array(1, 2, 1, 4, 2, 1);
$this->T128[] = array(1, 4, 1, 1, 2, 2);
$this->T128[] = array(1, 4, 1, 2, 2, 1);
$this->T128[] = array(1, 1, 2, 2, 1, 4);
$this->T128[] = array(1, 1, 2, 4, 1, 2);
$this->T128[] = array(1, 2, 2, 1, 1, 4);
$this->T128[] = array(1, 2, 2, 4, 1, 1);
$this->T128[] = array(1, 4, 2, 1, 1, 2);
$this->T128[] = array(1, 4, 2, 2, 1, 1);
$this->T128[] = array(2, 4, 1, 2, 1, 1);
$this->T128[] = array(2, 2, 1, 1, 1, 4);
$this->T128[] = array(4, 1, 3, 1, 1, 1);
$this->T128[] = array(2, 4, 1, 1, 1, 2);
$this->T128[] = array(1, 3, 4, 1, 1, 1);
$this->T128[] = array(1, 1, 1, 2, 4, 2);
$this->T128[] = array(1, 2, 1, 1, 4, 2);
$this->T128[] = array(1, 2, 1, 2, 4, 1);
$this->T128[] = array(1, 1, 4, 2, 1, 2);
$this->T128[] = array(1, 2, 4, 1, 1, 2);
$this->T128[] = array(1, 2, 4, 2, 1, 1);
$this->T128[] = array(4, 1, 1, 2, 1, 2);
$this->T128[] = array(4, 2, 1, 1, 1, 2);
$this->T128[] = array(4, 2, 1, 2, 1, 1);
$this->T128[] = array(2, 1, 2, 1, 4, 1);
$this->T128[] = array(2, 1, 4, 1, 2, 1);
$this->T128[] = array(4, 1, 2, 1, 2, 1);
$this->T128[] = array(1, 1, 1, 1, 4, 3);
$this->T128[] = array(1, 1, 1, 3, 4, 1);
$this->T128[] = array(1, 3, 1, 1, 4, 1);
$this->T128[] = array(1, 1, 4, 1, 1, 3);
$this->T128[] = array(1, 1, 4, 3, 1, 1);
$this->T128[] = array(4, 1, 1, 1, 1, 3);
$this->T128[] = array(4, 1, 1, 3, 1, 1);
$this->T128[] = array(1, 1, 3, 1, 4, 1);
$this->T128[] = array(1, 1, 4, 1, 3, 1);
$this->T128[] = array(3, 1, 1, 1, 4, 1);
$this->T128[] = array(4, 1, 1, 1, 3, 1);
$this->T128[] = array(2, 1, 1, 4, 1, 2);
$this->T128[] = array(2, 1, 1, 2, 1, 4);
$this->T128[] = array(2, 1, 1, 2, 3, 2);
$this->T128[] = array(2, 3, 3, 1, 1, 1);
$this->T128[] = array(2, 1);
for ($i = 32; $i <= 95; $i++) {
$this->ABCset .= chr($i);
}
$this->Aset = $this->ABCset;
$this->Bset = $this->ABCset;
for ($i = 0; $i <= 31; $i++) {
$this->ABCset .= chr($i);
$this->Aset .= chr($i);
}
for ($i = 96; $i <= 126; $i++) {
$this->ABCset .= chr($i);
$this->Bset .= chr($i);
}
$this->Cset="0123456789";
for ($i=0; $i<96; $i++) {
@$this->SetFrom["A"] .= chr($i);
@$this->SetFrom["B"] .= chr($i + 32);
@$this->SetTo["A"] .= chr(($i < 32) ? $i+64 : $i-32);
@$this->SetTo["B"] .= chr($i);
}
}
function Code128($x, $y, $code, $w, $h) {
$Aguid = "";
$Bguid = "";
$Cguid = "";
for ($i=0; $i < strlen($code); $i++) {
$needle = substr($code,$i,1);
$Aguid .= ((strpos($this->Aset,$needle)===false) ? "N" : "O");
$Bguid .= ((strpos($this->Bset,$needle)===false) ? "N" : "O");
$Cguid .= ((strpos($this->Cset,$needle)===false) ? "N" : "O");
}
$SminiC = "OOOO";
$IminiC = 4;
$crypt = "";
while ($code > "") {
$i = strpos($Cguid,$SminiC);
if ($i!==false) {
$Aguid [$i] = "N";
$Bguid [$i] = "N";
}
if (substr($Cguid,0,$IminiC) == $SminiC) {
$crypt .= chr(($crypt > "") ? $this->JSwap["C"] : $this->JStart["C"]);
$made = strpos($Cguid,"N");
if ($made === false) {
$made = strlen($Cguid);
}
if (fmod($made,2)==1) {
$made--;
}
for ($i=0; $i < $made; $i += 2) {
$crypt .= chr(strval(substr($code,$i,2)));
}
$jeu = "C";
} else {
$madeA = strpos($Aguid,"N");
if ($madeA === false) {
$madeA = strlen($Aguid);
}
$madeB = strpos($Bguid,"N");
if ($madeB === false) {
$madeB = strlen($Bguid);
}
$made = (($madeA < $madeB) ? $madeB : $madeA );
$jeu = (($madeA < $madeB) ? "B" : "A" );
$crypt .= chr(($crypt > "") ? $this->JSwap[$jeu] : $this->JStart[$jeu]);
$crypt .= strtr(substr($code, 0,$made), $this->SetFrom[$jeu], $this->SetTo[$jeu]);
}
$code = substr($code,$made);
$Aguid = substr($Aguid,$made);
$Bguid = substr($Bguid,$made);
$Cguid = substr($Cguid,$made);
}
$check = ord($crypt[0]);
for ($i=0; $i<strlen($crypt); $i++) {
$check += (ord($crypt[$i]) * $i);
}
$check %= 103;
$crypt .= chr($check) . chr(106) . chr(107);
$i = (strlen($crypt) * 11) - 8;
$modul = $w/$i;
for ($i=0; $i<strlen($crypt); $i++) {
$c = $this->T128[ord($crypt[$i])];
for ($j=0; $j<count($c); $j++) {
$this->Rect($x,$y,$c[$j]*$modul,$h,"F");
$x += ($c[$j++]+$c[$j])*$modul;
}
}
}
}
$pdf = new bezwaar();
$pdf->AliasNbPages();
$pdf->SetTopMargin(34.7);
$pdf->addPage();
$pdf->SetFont('Arial','',8);
$pdf->MultiCell(0,4,$inhoud);
$code='CODE 128';
$pdf->Code128(50,20,$code,80,20);
$pdf->SetXY(50,45);
$pdf->Write(5,'A set: "'.$code.'"');
$pdf->Output();