शीर्षक की तरह ही मुझे दो वर्गों के संयोजन में समस्याएं आ रही हैं। Altough यह एफपीडीएफ के बारे में है, मुझे लगता है कि यह एक नियमित सवाल है, क्योंकि सवाल किसी भी स्क्रिप्ट के बारे में हो सकता था।PHP: इन दो वर्गों को कैसे गठबंधन करें?
मैं फ्लाई पर पीडीएफ दस्तावेज़ बनाने के लिए एफपीडीएफ का उपयोग कर रहा हूं। पीडीएफ फाइल में वेक्टर छवियों को जोड़ने के लिए मैं इसे एफपीडीआई कक्षा के संयोजन में उपयोग करता हूं। लिपि नीचे पाई जा सकती है और एक आकर्षण की तरह काम करता है।
<?php
// Add FPDF to generate PDF files
require_once('../fpdf16/fpdf.php');
// Add FPDI to add the functionality of importing PDF files for layout purposes
require_once('../fpdi131/fpdi.php');
// Code128 to create barcodes
require('code128.php');
// Function that extends FPDI to import a PDF file for layout purposes
class bezwaar extends FPDI
{
//Page header
function Header()
{
global $tplidx;
global $pagecount;
$this->SetFont('Arial','',8); // Font
if($this->PageNo()>1) $this->SetY(62); // Margins
$pagecount = $this->setSourceFile('standaardbezwaar.pdf'); // Open template
$tplidx = $this->importPage(1, '/MediaBox'); // Template import
$this->useTemplate($tplidx, 0, 0, 210); // Margins, Margins, Width.
}
}
#### General settings
$pdf = new bezwaar();
$pdf->AliasNbPages(); // Add headers
$pdf->SetTopMargin(34.7); // Margins top
$pdf->addPage(); // Open page
$pdf->SetFont('Arial','',8); // Set font
#### Content;
$pdf->MultiCell(0,4,$inhoud); // $inhoud is content from a database
$pdf->Output();
?>
समस्या यह है कि मैं बारकोड को जोड़ने के लिए एक और वर्ग को जोड़ने के लिए चाहते हैं, लेकिन मैं यह है कि एकीकृत करने के लिए कैसे पता नहीं है। नीचे दी गई स्क्रिप्ट एफपीडीएफ के साथ स्वयं ठीक काम करती है, लेकिन एफपीडीआई संयुक्त के साथ नहीं।
<?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.'"');
?>
समस्या शायद क्योंकि मैं इन दोनों गठबंधन करने के लिए की जरूरत है:
<?php
// I don't know how to combine the two below, especially not since both extend another class..
class bezwaar extends FPDI { } // Extends FPDI
class PDF_Code128 extends FPDF { } // Extends FPDF
// And/Or
$pdf = new PDF_Code128();
$pdf = new bezwaar();
?>
सूत्रों का कहना है
FPDF: http://www.fpdf.org
FPDI: http://www.setasign.de/products/pdf-php-solutions/fpdi/
Barcodeclass: http://www.fpdf.org/en/script/script88.php
प्रश्न
किसी को भी मेरी मदद कर बाहर कर सके और मुझे बताएं कि दोनों स्क्रिप्ट (ऊपर) कैसे गठबंधन करें? मैं PHP में कोई नई बात नहीं कर रहा हूँ, लेकिन मैं वर्गों के साथ नया हूँ, यह बहुत कठिन बना रही है .. enter code here
परीक्षण और त्रुटि के संयोजन से ऊपर दो - उत्तरों के आधार पर अद्यतन मैं
require_once('../fpdf16/fpdf.php');
require_once('../fpdi131/fpdi.php');
require('code128.php');
// Klasse en functie voor de header
class bezwaar extends FPDI // for example
{
//Page header
function Header()
{
global $tplidx;
global $pagecount;
$this->SetFont('Arial','',8); // Font instellen
if($this->PageNo()>1) $this->SetY(62); // Pagina marge voor subpaginas
$pagecount = $this->setSourceFile('standaardbezwaar.pdf'); // Template openen
$tplidx = $this->importPage(1, '/MediaBox'); // Template importeren
$this->useTemplate($tplidx, 0, 0, 210); // Marge, Marge, Breedte.
}
/**
* the pdf object
* @var PDF_Code128
*/
protected $_pdf;
/**
* the code string
* @var string
*/
protected $_code = 'CODE 128';
/**
* the class constructor method (called automatically upon instantiation)
* @param PDF_Code128 $pdf
*/
public function __construct(PDF_Code128 $pdf)
{
$this->_pdf = $pdf;
parent::__construct(); // might be optional
}
public function setCode($code)
{
$this->_code = $code;
return $this;
}
public function getCode()
{
return $this->_code;
}
/**
* The code you had before (bad function name, I know)
*/
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(); // header
$pdf->SetTopMargin(34.7); // margins
$pdf->addPage(); // create new page
//Arial
$pdf->SetFont('Arial','',8);
//Output
$pdf->MultiCell(0,4,$inhoud);
$pdf->setPdfStuff();
$pdf->Output();
हो रही है त्रुटि
चेतावनी: शून्य से /home/fpdf16/fpdf.php में लाइन 812
एक और त्रि पर डिवीजन अल और त्रुटि
इस समय को छोड़कर यह आमतौर पर काम करता है। मैं बस विस्तारित एफपीडीआई कक्षा में बारकोड कक्षा के भीतर कार्यों को जोड़ रहा हूं। इसका नतीजा यह है कि जब तक मैंने इस पंक्ति को हटाया नहीं है तब तक स्क्रिप्ट का समय समाप्त होता है: $ pdf-> कोड 128 (50,20, $ कोड, 80,20), लेकिन बारकोड बनाने के लिए उस पंक्ति की आवश्यकता है। क्या किसी के पास कोई विचार है कि यह समय निकाल सकता है?
require_once('../fpdf16/fpdf.php');
require_once('../fpdi131/fpdi.php');
require('code128.php');
// Klasse en functie voor de header
class bezwaar extends FPDI
{
//Page header
function Header()
{
global $tplidx;
global $pagecount;
$this->SetFont('Arial','',8); // Font instellen
if($this->PageNo()>1) $this->SetY(62); // Pagina marge voor subpaginas
$pagecount = $this->setSourceFile('standaardbezwaar.pdf'); // Template openen
$tplidx = $this->importPage(1, '/MediaBox'); // Template importeren
$this->useTemplate($tplidx, 0, 0, 210); // Marge, Marge, Breedte.
}
var $T128; // tableau des codes 128
var $ABCset=""; // jeu des caractères éligibles au C128
var $Aset=""; // Set A du jeu des caractères éligibles
var $Bset=""; // Set B du jeu des caractères éligibles
var $Cset=""; // Set C du jeu des caractères éligibles
var $SetFrom; // Convertisseur source des jeux vers le tableau
var $SetTo; // Convertisseur destination des jeux vers le tableau
var $JStart = array("A"=>103, "B"=>104, "C"=>105); // Caractères de sélection de jeu au début du C128
var $JSwap = array("A"=>101, "B"=>100, "C"=>99); // Caractères de changement de jeu
//____________________________ Extension du constructeur _______________________
function PDF_Code128($orientation='P', $unit='mm', $format='A4') {
parent::FPDF($orientation,$unit,$format);
$this->T128[] = array(2, 1, 2, 2, 2, 2); //0 : [ ] // composition des caractères
$this->T128[] = array(2, 2, 2, 1, 2, 2); //1 : [!]
$this->T128[] = array(2, 2, 2, 2, 2, 1); //2 : ["]
$this->T128[] = array(1, 2, 1, 2, 2, 3); //3 : [#]
$this->T128[] = array(1, 2, 1, 3, 2, 2); //4 : [$]
$this->T128[] = array(1, 3, 1, 2, 2, 2); //5 : [%]
$this->T128[] = array(1, 2, 2, 2, 1, 3); //6 : [&]
$this->T128[] = array(1, 2, 2, 3, 1, 2); //7 : [']
$this->T128[] = array(1, 3, 2, 2, 1, 2); //8 : [(]
$this->T128[] = array(2, 2, 1, 2, 1, 3); //9 : [)]
$this->T128[] = array(2, 2, 1, 3, 1, 2); //10 : [*]
$this->T128[] = array(2, 3, 1, 2, 1, 2); //11 : [+]
$this->T128[] = array(1, 1, 2, 2, 3, 2); //12 : [,]
$this->T128[] = array(1, 2, 2, 1, 3, 2); //13 : [-]
$this->T128[] = array(1, 2, 2, 2, 3, 1); //14 : [.]
$this->T128[] = array(1, 1, 3, 2, 2, 2); //15 : [/]
$this->T128[] = array(1, 2, 3, 1, 2, 2); //16 : [0]
$this->T128[] = array(1, 2, 3, 2, 2, 1); //17 : [1]
$this->T128[] = array(2, 2, 3, 2, 1, 1); //18 : [2]
$this->T128[] = array(2, 2, 1, 1, 3, 2); //19 : [3]
$this->T128[] = array(2, 2, 1, 2, 3, 1); //20 : [4]
$this->T128[] = array(2, 1, 3, 2, 1, 2); //21 : [5]
$this->T128[] = array(2, 2, 3, 1, 1, 2); //22 : [6]
$this->T128[] = array(3, 1, 2, 1, 3, 1); //23 : [7]
$this->T128[] = array(3, 1, 1, 2, 2, 2); //24 : [8]
$this->T128[] = array(3, 2, 1, 1, 2, 2); //25 : [9]
$this->T128[] = array(3, 2, 1, 2, 2, 1); //26 : [:]
$this->T128[] = array(3, 1, 2, 2, 1, 2); //27 : [;]
$this->T128[] = array(3, 2, 2, 1, 1, 2); //28 : [<]
$this->T128[] = array(3, 2, 2, 2, 1, 1); //29 : [=]
$this->T128[] = array(2, 1, 2, 1, 2, 3); //30 : [>]
$this->T128[] = array(2, 1, 2, 3, 2, 1); //31 : [?]
$this->T128[] = array(2, 3, 2, 1, 2, 1); //32 : [@]
$this->T128[] = array(1, 1, 1, 3, 2, 3); //33 : [A]
$this->T128[] = array(1, 3, 1, 1, 2, 3); //34 : [B]
$this->T128[] = array(1, 3, 1, 3, 2, 1); //35 : [C]
$this->T128[] = array(1, 1, 2, 3, 1, 3); //36 : [D]
$this->T128[] = array(1, 3, 2, 1, 1, 3); //37 : [E]
$this->T128[] = array(1, 3, 2, 3, 1, 1); //38 : [F]
$this->T128[] = array(2, 1, 1, 3, 1, 3); //39 : [G]
$this->T128[] = array(2, 3, 1, 1, 1, 3); //40 : [H]
$this->T128[] = array(2, 3, 1, 3, 1, 1); //41 : [I]
$this->T128[] = array(1, 1, 2, 1, 3, 3); //42 : [J]
$this->T128[] = array(1, 1, 2, 3, 3, 1); //43 : [K]
$this->T128[] = array(1, 3, 2, 1, 3, 1); //44 : [L]
$this->T128[] = array(1, 1, 3, 1, 2, 3); //45 : [M]
$this->T128[] = array(1, 1, 3, 3, 2, 1); //46 : [N]
$this->T128[] = array(1, 3, 3, 1, 2, 1); //47 : [O]
$this->T128[] = array(3, 1, 3, 1, 2, 1); //48 : [P]
$this->T128[] = array(2, 1, 1, 3, 3, 1); //49 : [Q]
$this->T128[] = array(2, 3, 1, 1, 3, 1); //50 : [R]
$this->T128[] = array(2, 1, 3, 1, 1, 3); //51 : [S]
$this->T128[] = array(2, 1, 3, 3, 1, 1); //52 : [T]
$this->T128[] = array(2, 1, 3, 1, 3, 1); //53 : [U]
$this->T128[] = array(3, 1, 1, 1, 2, 3); //54 : [V]
$this->T128[] = array(3, 1, 1, 3, 2, 1); //55 : [W]
$this->T128[] = array(3, 3, 1, 1, 2, 1); //56 : [X]
$this->T128[] = array(3, 1, 2, 1, 1, 3); //57 : [Y]
$this->T128[] = array(3, 1, 2, 3, 1, 1); //58 : [Z]
$this->T128[] = array(3, 3, 2, 1, 1, 1); //59 : [[]
$this->T128[] = array(3, 1, 4, 1, 1, 1); //60 : [\]
$this->T128[] = array(2, 2, 1, 4, 1, 1); //61 : []]
$this->T128[] = array(4, 3, 1, 1, 1, 1); //62 : [^]
$this->T128[] = array(1, 1, 1, 2, 2, 4); //63 : [_]
$this->T128[] = array(1, 1, 1, 4, 2, 2); //64 : [`]
$this->T128[] = array(1, 2, 1, 1, 2, 4); //65 : [a]
$this->T128[] = array(1, 2, 1, 4, 2, 1); //66 : [b]
$this->T128[] = array(1, 4, 1, 1, 2, 2); //67 : [c]
$this->T128[] = array(1, 4, 1, 2, 2, 1); //68 : [d]
$this->T128[] = array(1, 1, 2, 2, 1, 4); //69 : [e]
$this->T128[] = array(1, 1, 2, 4, 1, 2); //70 : [f]
$this->T128[] = array(1, 2, 2, 1, 1, 4); //71 : [g]
$this->T128[] = array(1, 2, 2, 4, 1, 1); //72 : [h]
$this->T128[] = array(1, 4, 2, 1, 1, 2); //73 : [i]
$this->T128[] = array(1, 4, 2, 2, 1, 1); //74 : [j]
$this->T128[] = array(2, 4, 1, 2, 1, 1); //75 : [k]
$this->T128[] = array(2, 2, 1, 1, 1, 4); //76 : [l]
$this->T128[] = array(4, 1, 3, 1, 1, 1); //77 : [m]
$this->T128[] = array(2, 4, 1, 1, 1, 2); //78 : [n]
$this->T128[] = array(1, 3, 4, 1, 1, 1); //79 : [o]
$this->T128[] = array(1, 1, 1, 2, 4, 2); //80 : [p]
$this->T128[] = array(1, 2, 1, 1, 4, 2); //81 : [q]
$this->T128[] = array(1, 2, 1, 2, 4, 1); //82 : [r]
$this->T128[] = array(1, 1, 4, 2, 1, 2); //83 : [s]
$this->T128[] = array(1, 2, 4, 1, 1, 2); //84 : [t]
$this->T128[] = array(1, 2, 4, 2, 1, 1); //85 : [u]
$this->T128[] = array(4, 1, 1, 2, 1, 2); //86 : [v]
$this->T128[] = array(4, 2, 1, 1, 1, 2); //87 : [w]
$this->T128[] = array(4, 2, 1, 2, 1, 1); //88 : [x]
$this->T128[] = array(2, 1, 2, 1, 4, 1); //89 : [y]
$this->T128[] = array(2, 1, 4, 1, 2, 1); //90 : [z]
$this->T128[] = array(4, 1, 2, 1, 2, 1); //91 : [{]
$this->T128[] = array(1, 1, 1, 1, 4, 3); //92 : [|]
$this->T128[] = array(1, 1, 1, 3, 4, 1); //93 : [}]
$this->T128[] = array(1, 3, 1, 1, 4, 1); //94 : [~]
$this->T128[] = array(1, 1, 4, 1, 1, 3); //95 : [DEL]
$this->T128[] = array(1, 1, 4, 3, 1, 1); //96 : [FNC3]
$this->T128[] = array(4, 1, 1, 1, 1, 3); //97 : [FNC2]
$this->T128[] = array(4, 1, 1, 3, 1, 1); //98 : [SHIFT]
$this->T128[] = array(1, 1, 3, 1, 4, 1); //99 : [Cswap]
$this->T128[] = array(1, 1, 4, 1, 3, 1); //100 : [Bswap]
$this->T128[] = array(3, 1, 1, 1, 4, 1); //101 : [Aswap]
$this->T128[] = array(4, 1, 1, 1, 3, 1); //102 : [FNC1]
$this->T128[] = array(2, 1, 1, 4, 1, 2); //103 : [Astart]
$this->T128[] = array(2, 1, 1, 2, 1, 4); //104 : [Bstart]
$this->T128[] = array(2, 1, 1, 2, 3, 2); //105 : [Cstart]
$this->T128[] = array(2, 3, 3, 1, 1, 1); //106 : [STOP]
$this->T128[] = array(2, 1); //107 : [END BAR]
for ($i = 32; $i <= 95; $i++) { // jeux de caractères
$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="";
for ($i=0; $i<96; $i++) { // convertisseurs des jeux A & B
@$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);
}
}
//________________ Fonction encodage et dessin du code 128 _____________________
function Code128($x, $y, $code, $w, $h) {
$Aguid = ""; // Création des guides de choix ABC
$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 > "") {
// BOUCLE PRINCIPALE DE CODAGE
$i = strpos($Cguid,$SminiC); // forçage du jeu C, si possible
if ($i!==false) {
$Aguid [$i] = "N";
$Bguid [$i] = "N";
}
if (substr($Cguid,0,$IminiC) == $SminiC) { // jeu C
$crypt .= chr(($crypt > "") ? $this->JSwap["C"] : $this->JStart["C"]); // début Cstart, sinon Cswap
$made = strpos($Cguid,"N"); // étendu du set C
if ($made === false) {
$made = strlen($Cguid);
}
if (fmod($made,2)==1) {
$made--; // seulement un nombre pair
}
for ($i=0; $i < $made; $i += 2) {
$crypt .= chr(strval(substr($code,$i,2))); // conversion 2 par 2
}
$jeu = "C";
} else {
$madeA = strpos($Aguid,"N"); // étendu du set A
if ($madeA === false) {
$madeA = strlen($Aguid);
}
$madeB = strpos($Bguid,"N"); // étendu du set B
if ($madeB === false) {
$madeB = strlen($Bguid);
}
$made = (($madeA < $madeB) ? $madeB : $madeA); // étendu traitée
$jeu = (($madeA < $madeB) ? "B" : "A"); // Jeu en cours
$crypt .= chr(($crypt > "") ? $this->JSwap[$jeu] : $this->JStart[$jeu]); // début start, sinon swap
$crypt .= strtr(substr($code, 0,$made), $this->SetFrom[$jeu], $this->SetTo[$jeu]); // conversion selon jeu
}
$code = substr($code,$made); // raccourcir légende et guides de la zone traitée
$Aguid = substr($Aguid,$made);
$Bguid = substr($Bguid,$made);
$Cguid = substr($Cguid,$made);
} // FIN BOUCLE PRINCIPALE
$check = ord($crypt[0]); // calcul de la somme de contrôle
for ($i=0; $i<strlen($crypt); $i++) {
$check += (ord($crypt[$i]) * $i);
}
$check %= 103;
$crypt .= chr($check) . chr(106) . chr(107); // Chaine Cryptée complète
$i = (strlen($crypt) * 11) - 8; // calcul de la largeur du module
$modul = $w/$i;
for ($i=0; $i<strlen($crypt); $i++) { // BOUCLE D'IMPRESSION
$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 aanmaken met nieuwe klasses en functies
$pdf->AliasNbPages(); // Toevoeging voor headers
$pdf->SetTopMargin(34.7); // Marge bovenkant instellen
$pdf->addPage(); // Pagina openen
//Arial
$pdf->SetFont('Arial','',8);
//Output inhoud
$pdf->MultiCell(0,4,$inhoud);
//A set
$code='CODE 128';
$pdf->Code128(50,20,$code,80,20);
$pdf->SetXY(50,45);
$pdf->Write(5,'A set: "'.$code.'"');
$pdf->Output();
मैं पूरी तरह से समझ में नहीं आता कि आप क्या क्या कोड यहाँ के साथ चल रहा है प्राप्त करने के लिए कोशिश कर रहे हैं या है, लेकिन कर सकते हैं आप 'पीडीएफ_Code128' के आउटपुट को' बेजवायर 'में' $ pdf = new bezwaar ($ pdf) जैसे पास करते हैं; '। फिर 'बेजवायर' कन्स्ट्रक्टर में आप 'PDF_Code128' के आउटपुट तक पूर्ण पहुंच प्राप्त कर सकते हैं। – Treffynnon
मैं पूरी तरह समझ नहीं पा रहा हूं कि आपका क्या मतलब है। अब मैं यह कोशिश कर रहा हूं (मैं समझता हूं कि यह शायद पागल है, लेकिन मैं अब घंटों के लिए चीजों की कोशिश कर रहा हूं) $ pdf = new bezwaar(); $ पीडीएफ = नया पीडीएफ_Code128 ($ पीडीएफ); – mat
@mmmshuddup ने मेरे विचार पर विस्तार किया है, जो इसे और अधिक स्पष्ट रूप से बताता है। – Treffynnon