Viewing file: PdfFact.php (5.61 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); // Incluimos el archivo fpdf require_once APPPATH."/third_party/fpdf.php"; //Extendemos la clase Pdf de la clase fpdf para que herede todas sus variables y funciones class PdfFact extends FPDF { public function __construct() { parent::__construct(); }
public function Code39($xpos, $ypos, $code, $baseline, $height){ $wide = $baseline; $narrow = $baseline / 3 ; $gap = $narrow; $barChar['0'] = 'nnnwwnwnn'; $barChar['1'] = 'wnnwnnnnw'; $barChar['2'] = 'nnwwnnnnw'; $barChar['3'] = 'wnwwnnnnn'; $barChar['4'] = 'nnnwwnnnw'; $barChar['5'] = 'wnnwwnnnn'; $barChar['6'] = 'nnwwwnnnn'; $barChar['7'] = 'nnnwnnwnw'; $barChar['8'] = 'wnnwnnwnn'; $barChar['9'] = 'nnwwnnwnn'; $barChar['A'] = 'wnnnnwnnw'; $barChar['B'] = 'nnwnnwnnw'; $barChar['C'] = 'wnwnnwnnn'; $barChar['D'] = 'nnnnwwnnw'; $barChar['E'] = 'wnnnwwnnn'; $barChar['F'] = 'nnwnwwnnn'; $barChar['G'] = 'nnnnnwwnw'; $barChar['H'] = 'wnnnnwwnn'; $barChar['I'] = 'nnwnnwwnn'; $barChar['J'] = 'nnnnwwwnn'; $barChar['K'] = 'wnnnnnnww'; $barChar['L'] = 'nnwnnnnww'; $barChar['M'] = 'wnwnnnnwn'; $barChar['N'] = 'nnnnwnnww'; $barChar['O'] = 'wnnnwnnwn'; $barChar['P'] = 'nnwnwnnwn'; $barChar['Q'] = 'nnnnnnwww'; $barChar['R'] = 'wnnnnnwwn'; $barChar['S'] = 'nnwnnnwwn'; $barChar['T'] = 'nnnnwnwwn'; $barChar['U'] = 'wwnnnnnnw'; $barChar['V'] = 'nwwnnnnnw'; $barChar['W'] = 'wwwnnnnnn'; $barChar['X'] = 'nwnnwnnnw'; $barChar['Y'] = 'wwnnwnnnn'; $barChar['Z'] = 'nwwnwnnnn'; $barChar['-'] = 'nwnnnnwnw'; $barChar['.'] = 'wwnnnnwnn'; $barChar[' '] = 'nwwnnnwnn'; $barChar['*'] = 'nwnnwnwnn'; $barChar['$'] = 'nwnwnwnnn'; $barChar['/'] = 'nwnwnnnwn'; $barChar['+'] = 'nwnnnwnwn'; $barChar['%'] = 'nnnwnwnwn'; $this->SetFont('Arial','',10); $this->Text($xpos+10, $ypos + $height + 4, $code); $this->SetFillColor(0); $code = '*'.strtoupper($code).'*'; for($i=0; $i<strlen($code); $i++){ $char = $code[$i]; if(!isset($barChar[$char])){ $this->Error('Invalid character in barcode: '.$char); } $seq = $barChar[$char]; for($bar=0; $bar<9; $bar++){ if($seq[$bar] == 'n'){ $lineWidth = $narrow; }else{ $lineWidth = $wide; } if($bar % 2 == 0){ $this->Rect($xpos, $ypos, $lineWidth, $height, 'F'); } $xpos += $lineWidth; } $xpos += $gap; } /* $wide = $basewidth; $narrow = $basewidth / 3 ; // wide/narrow codes for the digits $barChar['0'] = 'nnwwn'; $barChar['1'] = 'wnnnw'; $barChar['2'] = 'nwnnw'; $barChar['3'] = 'wwnnn'; $barChar['4'] = 'nnwnw'; $barChar['5'] = 'wnwnn'; $barChar['6'] = 'nwwnn'; $barChar['7'] = 'nnnww'; $barChar['8'] = 'wnnwn'; $barChar['9'] = 'nwnwn'; $barChar['A'] = 'nn'; $barChar['Z'] = 'wn'; // add leading zero if code-length is odd if(strlen($code) % 2 != 0){ $code = '0' . $code; } $this->SetFont('Arial', '', 10); $this->Text($xpos, $ypos + $height + 4, $code); $this->SetFillColor(0); // add start and stop codes $code = 'AA'.strtolower($code).'ZA';
for($i=0; $i<strlen($code); $i=$i+2){ // choose next pair of digits $charBar = $code{$i}; $charSpace = $code{$i+1}; // check whether it is a valid digit if(!isset($barChar[$charBar])){ $this->Error('Invalid character in barcode: '.$charBar); } if(!isset($barChar[$charSpace])){ $this->Error('Invalid character in barcode: '.$charSpace); } // create a wide/narrow-sequence (first digit=bars, second digit=spaces) $seq = ''; for($s=0; $s<strlen($barChar[$charBar]); $s++){ $seq .= $barChar[$charBar]{$s} . $barChar[$charSpace]{$s}; }
for($bar=0; $bar<strlen($seq); $bar++){ // set lineWidth depending on value if($seq{$bar} == 'n'){ $lineWidth = $narrow; }else{ $lineWidth = $wide; } // draw every second value, because the second digit of the pair is represented by the spaces if($bar % 2 == 0){ $this->Rect($xpos, $ypos, $lineWidth, $height, 'F'); } $xpos += $lineWidth; } }*/ } // El encabezado del PDF public function Header(){ // $this->Image('/third_party/tutorial/logo.png',10,8,22);
$this->SetFont('Helvetica', 'B', 18); $this->Cell(85); $this->Cell(20,10,'A',1,0,'C'); $this->Cell(85,7,"FACTURA",0,0,'R','0'); $this->Ln(9); $this->SetFont('Helvetica','B',6); $this->Cell(100,5,'Codigo 01',0,0,'R');
} // El pie del pdf public function Footer(){ // $this->SetY(-15); // $this->SetFont('Arial','I',8); // $this->Cell(0,10,'Pagina '.$this->PageNo().'/{nb}',0,0,'C'); } } ?>;
|