  | 
              
	              
	                
  
    
	 
        ทำ Barcode 128 มีปัญหาตรง อักขระพิเศษ Carriage Return(CR)     | 
   
  
    |   | 
   
 
 
 
	
		
			  | 
	   | 
	    | 
		
			  | 
	 
	
		
			  | 
		 		   | 
	  	    
          
            
			
	
			
			 
                ตามที่ธนาคารแห่งประเทศไทยได้ประกาศมาตรฐาน ตามลิงค์ 
 
http://www.bot.or.th/Thai/PaymentSystems/PSServices/StandardPS/DocLib/Std_Barcode.pdf 
 
ตอนนี้ผมใช้ Class PHP จาก http://barcode-coder.com/en/barcode-php-class-203.html  
 
ติดปัญหาตรงที่ ธนาคารให้ใส่ Carriage Return(CR) เพื่อขึ้นบรรทัดใหม่ ใครที่เคยทำช่วยแนะนำด้วยครับ ตอนนี้คิดไม่ออกเลย 
 
ผมอ่านตามลิงค์ https://www.thaicreate.com/asp/forum/082058.html ก็ยังไม่ได้ 
 
ไฟล์ที่ผมลองทำ ตามนี้ครับ  
 
https://drive.google.com/file/d/0B1Lv1k3Ur2MvbFdxXzVFZzh2c2M/view?usp=sharing 
 
Code (PHP) 
<?php
	include('./class-barcode/php-barcode.php');
	require('fpdf.php');
	// Start Bar-Code
			  // -------------------------------------------------- //
			  //                      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 = 10;
			  $marge    = 10;	   // between barcode and hri in pixel
			  $x        = 200;			// barcode center
			  $y        = 200;			 // barcode center
			  $height   = 50;		// barcode height in 1D ; module size in 2D
			  $width    = 2;			 // barcode height in 1D ; not use in 2D
			  $angle    = 0;			// rotation in degrees
			  
			 $ddd="12345";
			  $code     = "$ddd"; // barcode, of course ;)
			  $type     = 'code128';
			  $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
			  // -------------------------------------------------- //
	// End Bar-Code
	define('FPDF_FONTPATH','font/');
	$pdf->AddFont('angsa','','angsa.php');
	$pdf->SetFont('angsa','',10);
	$len = $pdf->GetStringWidth($data['hri']);
	  Barcode::rotate(-$len / 2, ($data['height'] / 2) + 15 + $marge, $angle, $xt, $yt);
	  $pdf->TextWithRotation($x + $xt, $y + $yt, $data['hri'], $angle);
	$pdf->Cell(0,20,iconv( 'UTF-8','TIS-620','ทดสอบ'),0,1,"C");
	//$pdf->Output("MyPDF/MyPDF.pdf","F");
	$pdf->Output();
?>
 
 
  Tag : PHP, MySQL               
                        | 
           
          
            
		
  ประวัติการแก้ไข 2014-10-15 09:49:18	
                             | 
           
          
            
              
                   | 
                   | 
                   | 
               
              
                   | 
                
                    
                      | Date :
                          2014-10-15 09:39:13 | 
                      By :
                          Berbatov23 | 
                      View :
                          13917 | 
                      Reply :
                          17 | 
                     
                  | 
                   | 
               
              
                   | 
                   | 
                   | 
               
              | 
           
          
            | 
			 | 
           
         
	    
		             | 
		
			  | 
	 
	
		
			  | 
		  | 
		
			  | 
		
			  | 
	 
 
              
  
          
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 Mac: \r 
Linux/Unix: \n 
Windows: \r\n                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2014-10-15 09:51:05 | 
                        By :
                            gaowteen | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 Code (PHP) 
$ddd="12345";
  
 
ผมลองใส่เป็น  
 
Code (PHP) 
$ddd="12345\r\n6789";
  
 
ตามที่คุณ BIrD แนะนำแล้วบาร์โค๊ด ไม่ขึ้นเลย หรือผมเข้าใจผิดครับ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2014-10-15 09:57:17 | 
                        By :
                            Berbatov23 | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ตามที่ผมอ่าน นะ ครับ 
- จัดพิมพดวย Code 128 จํานวน 62 หลัก (ไมรวม Carriage Return ) อยูในแถวเดียวกันจํานวน 1 แทง                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2014-10-15 10:02:21 | 
                        By :
                            gaowteen | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 12345<CR>6789 แบบนี้ได้ปะ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2014-10-15 10:29:26 | 
                        By :
                            gaowteen | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ของเราเครื่องมันไม่อ่านเลยอ่ะ หรือถ้าอ่านก็จะขึ้นว่า TYPE UPC_E แล้วก็ขึ้นเลขอะไรไม่รู้ประมาณ 6 หลัก ทั้งๆที่จริงๆมีตัวเลขมากกว่านั้น และใช้ฟอนต์ code128 รบกวนขอคำชี้แนะจากผู้รู้ด้วยจร้า ตอนนี้เราขอแค่อ่านได้ก่อนก็พอ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2015-07-22 11:23:13 | 
                        By :
                            ัyyy | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ลองเอาโค๊ดมาแปะ ดูครับ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2015-07-22 13:21:39 | 
                        By :
                            NewbiePHP | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 Code (PHP) 
<?php 	 
//	ฟังก์ชั่น บาร์โค๊ด
		$images = ImageCreate(500,50);     //ความกว้าง ความสูง ของกรอบบาร์โค้ด
		$color = ImageColorAllocate($images,255,255,255);
		$white = ImageColorAllocate($images, 255, 255, 255);
		$blue = ImageColorAllocate($images, 0, 0, 255);
		ImageRectangle($images, 0, 0, 299, 69, $color);
		$text="12345 6789";
		$font = 'code128.TTF';        //FONT
		
		$white = ImageColorAllocate($images, 255, 255, 255);
		$blue = ImageColorAllocate($images, 0, 0, 255);
		ImagettfText($images, 27, 0, 15, 35, $blue, $font, $text);  //ตำแหน่ง text บาร์โค้ด
		
		ImagePng($images,"MyResize/image.png");
		ImageDestroy($images);
php?>
	     <img src=MyResize/image.png width="337" height="32"> <br>
             <? echo $text; ?>
 
 
 
                         
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2015-07-22 17:15:51 | 
                        By :
                            ัyyy | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 จากตัวอย่าง ใช้ code แค่นี้ค่ะ แล้วก็ดาวน์โหลด font code128.TTF มาไว้ที่โฟลเดอร์โปรเจ็ค 
ส่วน text เป็นข้อมูลตัวอย่างค่ะ รบกวนด้วยนะคะ ขอบคุณค่ะ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2015-07-22 17:17:59 | 
                        By :
                            yyy | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 หมายความว่าเครื่อง อ่านๆ จาก barcode ที่เราพิมพ์ออกมาไม่ได้ใช่ไหมครับ 
 
ลองกำหนด size ให้มันใหญ่ขึ้น ดูครับ บางทีมันเล็กไป หรือไม่ก็หาเครื่อง lazer มาลองพิมพ์แล้วทดสอบดูครับ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2015-07-22 18:14:26 | 
                        By :
                            NewbiePHP | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ผมทำแบบนี้ได้นะครับ 
$BCODE= "|123542\n253652\n4855858\n30000"; 
 
ผลลัพธ์จะออกมาแบบนี้ 
(แท่งบาร์โค้ด) 
|123542 253652 4855858 30000 
 
พอเอาเครื่องอ่านบาร์โค้ดมายิง มันจะขึ้นแบบนี้ 
|123542 
253652 
4855858 
30000 
 
 
ผมใช้กับ tcpdf  นะครับ 
$BCODE= "|123542\n253652\n4855858\n30000"; 
$params = TCPDF_STATIC::serializeTCPDFtagParameters(array($BCODE, 'C128', '', '', 180, 15, 0.9, array('position'=>'S','align' => 'C', 'border'=>true, 'padding'=>1, 'fgcolor'=>array(0,0,0), 'bgcolor'=>array(255,255,255), 'text'=>true, 'font'=>'helvetica', 'fontsize'=>10, 'stretchtext'=>10), 'N')); 
 
ลองดูครับ หรือว่าทำได้แล้วนะ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2016-03-31 09:03:11 | 
                        By :
                            พิภพ อินต๊ะภา | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ขอบคุณ คุณพิภพ มากครับ กำลังหาวิธีของ TCPDF อยู่พอดี                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2017-01-24 13:50:31 | 
                        By :
                            KOB | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 เข้ามาแชร์ข้อมูลเพิ่มเติมครับ 
 
ผมใช้ Library ของ https://github.com/picqer/php-barcode-generator 
 
การเรียกใช้งาน 
 
$barcode = "|$line1\n$line2\n$line3\n$line4"; 
$generatorPNG = new Picqer\Barcode\BarcodeGeneratorPNG(); 
$output = '<img width="380" height="35" src="data:image/png;base64,' . base64_encode($generatorPNG->getBarcode($barcode, $generatorPNG::TYPE_CODE_128)) . '">'; 
 
ทดสอบแล้ว Scan ได้ ขึ้นบรรทัดใหม่แบบสวยงามครับ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2021-10-07 21:43:06 | 
                        By :
                            Barnaby | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
      		  
	
     | 
   
 
                 |