SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP barcode generator code print in ZEBRA printer

    Hi,

    I just created a barcode image generator where I found out in internet, when I test it and I print it in a ordinary printer it was okay. Same size, what the barcode display on my web page is the same size of what I got printed, but when I tried to print it on Zebra Barcode Printer its become small and only half was printed.


    this is my code:
    PHP Code:
    <?php

    $bc 
    = new barCode();
    $bc->build($_GET['id']);

    $q = new MySQL();
    $q->Fetch(wms_receiving);
    class 
    barCode
    {
        public 
    $bcHeight$bcThinWidth$bcThickWidth$bcFontSize$mode;
        
       
    // function __construct($mode='gif', $height=25, $thin=1, $thick=3, $fSize=2)
       
    function __construct($mode='gif'$height=75$thin=1$thick=4$fSize=3)
        {
            
    $this->bcHeight $height;
            
    $this->bcThinWidth $thin;
            
    $this->bcThickWidth $this->bcThinWidth $thick;
            
    $this->fontSize $fSize;
            
    $this->mode $mode;       
            
    $this->outMode = array('gif'=>'gif''png'=>'png''jpeg'=>'jpeg''wbmp'=>'vnd.wap.wbmp');
            
    $this->codeMap = array(
                
    '0'=>'010000101',    '1'=>'100100001',    '2'=>'001100001',    '3'=>'101100000',
                
    '4'=>'000110001',    '5'=>'100110000',    '6'=>'001110000',    '7'=>'000100101',    
                
    '8'=>'100100100',    '9'=>'001100100',    'A'=>'100001001',    'B'=>'001001001',
                
    'C'=>'101001000',    'D'=>'000011001',    'E'=>'100011000',    'F'=>'001011000',
                
    'G'=>'000001101',    'H'=>'100001100',    'I'=>'001001100',    'J'=>'000011100',
                
    'K'=>'100000011',    'L'=>'001000011',    'M'=>'101000010',    'N'=>'000010011',
                
    'O'=>'100010010',    'P'=>'001010010',    'Q'=>'000000111',    'R'=>'100000110',
                
    'S'=>'001000110',    'T'=>'000010110',    'U'=>'110000001',    'V'=>'011000001',
                
    'W'=>'111000000',    'X'=>'010010001',    'Y'=>'110010000',    'Z'=>'011010000',
                
    ' '=>'011000100',    '$'=>'010101000',    '%'=>'000101010',    '*'=>'010010100',
                
    '+'=>'010001010',    '-'=>'000110100',    '.'=>'110000100',    '/'=>'010100010'
                
    );        
        }
        

        
        public function 
    build($text=''$showText=false$fileName=null)
        {   
            if (
    trim($text) <= ' '
                throw new 
    exception('barCode::build - must be passed text to operate');
            if (!
    $fileType $this->outMode[$this->mode]) 
                throw new 
    exception("barCode::build - unrecognized output format ({$this->mode})");
            if (!
    function_exists("image{$this->mode}")) 
                throw new 
    exception("barCode::build - unsupported output format ({$this->mode} - check phpinfo)");
      
            
    $text  =  strtoupper($text);
            
    $dispText "* $text *";
            
    $text "*$text*"// adds start and stop chars
            
    $textLen  =  strlen($text); 
            
    $barcodeWidth  =  $textLen * ($this->bcThinWidth $this->bcThickWidth) - $this->bcThinWidth
            
    $im imagecreate($barcodeWidth$this->bcHeight); 
            
    $black imagecolorallocate($im000); 
            
    $white imagecolorallocate($im255255255); 
            
    imagefill($im00$white); 
            
            
    $xpos 0;
            for (
    $idx=0$idx<$textLen$idx++)
            { 
                if (!
    $char $text[$idx]) $char '-';
                for (
    $ptr=0$ptr<=8$ptr++)
                { 
                    
    $elementWidth = ($this->codeMap[$char][$ptr]) ? $this->bcThickWidth $this->bcThinWidth
                    if ((
    $ptr 1) % 2
                        
    imagefilledrectangle($im$xpos0$xpos $elementWidth-1$this->bcHeight$black); 
                    
    $xpos += $elementWidth
                }
                
    $xpos += $this->bcThinWidth
            }
            
            if (
    $showText)
            {
                
    $pxWid imagefontwidth($this->fontSize) * strlen($dispText) + 10;
                
    $pxHt imagefontheight($this->fontSize) + 2;
                
    $bigCenter $barcodeWidth 2;
                
    $textCenter $pxWid 2;
                
    imagefilledrectangle($im$bigCenter $textCenter$this->bcHeight $pxHt$bigCenter $textCenter$this->bcHeight$white);
                
    imagestring($im$this->fontSize, ($bigCenter $textCenter) + 5, ($this->bcHeight $pxHt) + 1$dispText$black);
            }

            if (!
    $fileNameheader("Content-type:  image/{$fileType}");
            switch(
    $this->mode)
            {
                case 
    'gif'imagegif($im$fileName);
                case 
    'png'imagepng($im$fileName);
                case 
    'jpeg'imagejpeg($im$fileName);
                case 
    'wbmp'imagewbmp($im$fileName);
            }

            
    imagedestroy($im);         
        }
    }

    ?>
    I don't have any idea how can I print my barcode image in Zebra. Is this any configuration?


    Thank you

  2. #2
    SitePoint Guru bronze trophy
    Join Date
    Dec 2003
    Location
    Poland
    Posts
    930
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    The problem may not be with your script at all but probably with the way your system communicates with the printer. We have a Zebra thermal printer for printing UPS labels and printing GIF images doesn't produce good results. It's as if the standard driver for printing bitmap graphics is only provided as a last resort so that is works somehow. You may try tinkering with your driver settings. The best quality comes when we print labels provided in EPL format with the use of a special driver. I don't know if that is the problem in your case but I suppose if you had a php script that generated barcodes in EPL then they would print best. Of course, if you wanted to print EPL barcodes from a browser you might need a special plugin or java applet that would allow you to do that.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •