-
Need guidance printing a 128 barcode with fpdf
Need to place a database generated 128 bar code on a fpdf label (lower right corner). No idea where to start with barcode script.
Code:
<?php
require('fpdf.php');
$monthCode = array("02", "03", "04", "06", "09", "10", "10", "11", "11", "12", "12", "01");
$monthLetterCode = array("A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M");
$realMonthCode = date("n");
$labelYearCode = date("y");
$arrayMonthCode = $realMonthCode - 1;
$labelMonthCode = $monthCode[$arrayMonthCode];
$labelLetterCode = $monthLetterCode[$arrayMonthCode];
$myString = "Sh" . $labelMonthCode . $labelYearCode . $labelLetterCode;
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,12,'P4-830R',0,1);
$pdf->SetFont('Arial','B',8);
$pdf->Cell(40,5,'Suntec "A" Series Fuel Unit',0,1);
$pdf->Cell(40,5,'Kerosene Only',0,1);
$pdf->SetFont('Arial','B',6);
$pdf->Cell(3,5,'OEM');
$pdf->SetFont('Arial','',6);
$pdf->Cell(3);
$pdf->Cell(3,5,'#A1VA-7112');
$pdf->Cell(10);
$pdf->SetFont('Arial','B',6);
$pdf->Cell(3,5,'STG');
$pdf->SetFont('Arial','',6);
$pdf->Cell(3);
$pdf->Cell(3,5,'Single');
$pdf->Cell(10);
$pdf->SetFont('Arial','B',6);
$pdf->Cell(3,5,'ROT');
$pdf->SetFont('Arial','',6);
$pdf->Cell(3);
$pdf->Cell(3,5,'CW-R',0);
$pdf->Cell(35);
$pdf->Cell(3,5,$myString,0,1);
$pdf->SetFont('Arial','B',6);
$pdf->Cell(3,5,'MNT');
$pdf->SetFont('Arial','',6);
$pdf->Cell(3);
$pdf->Cell(3,5,'Flange');
$pdf->Cell(10);
$pdf->SetFont('Arial','B',6);
$pdf->Cell(3,5,'STG');
$pdf->SetFont('Arial','',6);
$pdf->Cell(3);
$pdf->Cell(3,5,'Single');
$pdf->Cell(10);
$pdf->SetFont('Arial','B',6);
$pdf->Cell(3,5,'ROT');
$pdf->SetFont('Arial','',6);
$pdf->Cell(3);
$pdf->Cell(3,5,'CW-R',0,1);
$pdf->SetFont('Arial','',4);
$pdf->Cell(80,5,'Sid Harvey Industries, Inc. 605 Locust St., Garden City, NY 11530',0,0,'C');
$pdf->Image('Sid.JPG',90,10,15,15);
$pdf->Output();
?>
-
UPC-A (not 128), oops!
Looking at http://barcode-coder.com/en/barcode-php-class-203.html
Have a sample running, but it's pretty unreadable at the size my label uses.
Code:
<?php
include('../php-barcode.php');
require('fpdf.php');
// -------------------------------------------------- //
// USEFUL
// -------------------------------------------------- //
class eFPDF extends FPDF{
function TextWithRotation($x, $y, $txt, $txt_angle, $font_angle=0)
{
$font_angle+=90+$txt_angle;
$txt_angle*=M_PI/180;
$font_angle*=M_PI/180;
$txt_dx=cos($txt_angle);
$txt_dy=sin($txt_angle);
$font_dx=cos($font_angle);
$font_dy=sin($font_angle);
$s=sprintf('BT %.2F %.2F %.2F %.2F %.2F %.2F Tm (%s) Tj ET',$txt_dx,$txt_dy,$font_dx,$font_dy,$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt));
if ($this->ColorFlag)
$s='q '.$this->TextColor.' '.$s.' Q';
$this->_out($s);
}
}
// -------------------------------------------------- //
// PROPERTIES
// -------------------------------------------------- //
$fontSize = 5;
$marge = 3; // between barcode and hri in pixel
$x = 200; // barcode center
$y = 75; // barcode center
$height = 15; // barcode height in 1D ; module size in 2D
$width = .4; // barcode width in 1D ; not use in 2D
$angle = 0; // rotation in degrees
$code = '0123456789012'; // barcode, of course ;)
$type = 'ean13';
$black = '000000'; // color in hexa
// -------------------------------------------------- //
// ALLOCATE FPDF RESSOURCE
// -------------------------------------------------- //
$pdf = new eFPDF('P', 'pt');
$pdf->AddPage();
// -------------------------------------------------- //
// BARCODE
// -------------------------------------------------- //
$data = Barcode::fpdf($pdf, $black, $x, $y, $angle, $type, array('code'=>$code), $width, $height);
// -------------------------------------------------- //
// HRI
// -------------------------------------------------- //
$pdf->SetFont('Arial','B',$fontSize);
$pdf->SetTextColor(0, 0, 0);
$len = $pdf->GetStringWidth($data['hri']);
Barcode::rotate(-$len / 2, ($data['height'] / 2) + $fontSize + $marge, $angle, $xt, $yt);
$pdf->TextWithRotation($x + $xt, $y + $yt, $data['hri'], $angle);
$pdf->Output();
?>
-
Alternatively, I have a UPC-A truetype font, but having issues displaying it with imagettftext. Any suggestions?
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
|
Bookmarks