www.webdeveloper.com
Results 1 to 10 of 10

Thread: Need guidance printing a 128 barcode with fpdf

  1. #1
    Join Date
    Mar 2013
    Location
    Andrews, SC
    Posts
    7

    Unhappy 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();
    ?>

  2. #2
    Join Date
    Mar 2013
    Location
    Andrews, SC
    Posts
    7

    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();
    ?>

  3. #3
    Join Date
    Mar 2013
    Location
    Andrews, SC
    Posts
    7
    Alternatively, I have a UPC-A truetype font, but having issues displaying it with imagettftext. Any suggestions?

  4. #4
    Join Date
    Jun 2013
    Posts
    37
    Did you mean that you need a help on how to created and display UPC-A barcode on image? or Code 128 generating tutorial? here is a UPC-A image barcode generating tutorial in c# .net, take a look and if you got any question,you can email for support.

  5. #5
    Join Date
    Mar 2013
    Location
    Andrews, SC
    Posts
    7
    Quote Originally Posted by Alcottpdf View Post
    Did you mean that you need a help on how to created and display UPC-A barcode on image? or Code 128 generating tutorial? here is a UPC-A image barcode generating tutorial in c# .net, take a look and if you got any question,you can email for support.
    I'm not using C#, I'm using php/fpdf. You did read the subject line, right? I needed the syntax for telling fpdf to display a barcode from a database field of 12 digits.

    It was:

    //barcode
    $pdf->setXY(0,0);
    $pdf->write1DBarcode($row['Bar Code'], 'UPCA', 2.875, 1.125, .625, 0.3125, '', array('text'=>true,'fontsize' => 6,'font' => 'helvetica'), 'M');

  6. #6
    Join Date
    Aug 2013
    Posts
    1
    I am not familiar with php. I only created UPC-A barcode in .NET. You may take a look at the professional barcode site to find php related barcode tool. Hope this is good clue. I can only offer this info.

  7. #7
    Join Date
    Aug 2013
    Posts
    30
    er, i'm not so clear about this problem,but i wanna offer you a resource about upc-a barcode generator displayed on google,you may take a look and find a clue

  8. #8
    Join Date
    Apr 2012
    Posts
    38
    Since fpdf has an integrated barcode function this might be useful:

    http://www.fpdf.org/en/script/script5.php

  9. #9
    Join Date
    Aug 2013
    Posts
    30
    Quote Originally Posted by versiondays View Post
    I am not familiar with php. I only created UPC-A barcode in .NET. You may take a look at the professional barcode site to find php related barcode tool. Hope this is good clue. I can only offer this info.
    hey , does it have the free trail version ?

  10. #10
    Join Date
    May 2014
    Location
    Walnut
    Posts
    1

    Only free to test

    Quote Originally Posted by cindy313 View Post
    I am not familiar with php. I only created UPC-A barcode in .NET. You may take a look at the professional barcode site to find php related barcode tool. Hope this is good clue. I can only offer this info.

    hey , does it have the free trail version ?
    As i know, this barcode tool is free to test and i've ever gotten a free evaluation from online.

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
  •  
HTML5 Development Center



Recent Articles