PHP - Barcode In Pdf
so I have this code that makes a barcode:
Code: [Select] <?php session_start(); // Must start session first thing /* Created By Adam Khoury @ www.flashbuilding.com -----------------------June 20, 2008----------------------- */ // Here we run a login check if (!isset($_SESSION['id'])) { echo 'Please <a href="login.php">log in</a> to access your account'; exit(); } //Connect to the database through our include include_once "connect_to_mysql.php"; // Place Session variable 'id' into local variable $userid = $_SESSION['id']; // Query member data from the database and ready it for display $sql = mysql_query("SELECT * FROM members WHERE userid='$userid' LIMIT 1"); while($row = mysql_fetch_array($sql)){ $name = $row['name']; $phone = $row["phone"]; $username = $row["username"]; $address = $row["address"]; $city = $row["city"]; $state = $row["state"]; $zip = $row["zip"]; $cell = $row["cell"]; $email = $row["email"]; $accounttype = $row["accounttype"]; $rank = $row["rank"]; $badges = $row["badges"]; } $sql = mysql_query("SELECT * FROM Events WHERE userid='$userid' && eventid=".$_GET['eventid'].""); while($row = mysql_fetch_array($sql)){ $price1 = $row['price1']; $price2 = $row["price2"]; $price3 = $row["price3"]; $price4 = $row["price4"]; $price5 = $row["price5"]; $price6 = $row["price6"]; $price7 = $row["price7"]; $price8 = $row["price8"]; $title1 = $row['title1']; $title2 = $row['title2']; $title3 = $row['title3']; $title4 = $row['title4']; $title5 = $row['title5']; $title6 = $row['title6']; $title7 = $row['title7']; $title8 = $row['title8']; $barcode1 = $row['barcode']; } $total = $price1 + $price2 + $price3 + $price4 +$price5 + $price6 + $price7 + $price8; require('fpdf.php'); class PDF extends FPDF { function EAN13($x=1, $y, $barcode, $h=16, $w=.35) { $this->Barcode(13,200,$barcode,$h,$w,13); } function UPC_A($x, $y, $barcode, $h=16, $w=.35) { $this->Barcode($x,$y,$barcode,$h,$w,12); } function GetCheckDigit($barcode) { //Compute the check digit $sum=0; for($i=1;$i<=11;$i+=2) $sum+=3*$barcode[$i]; for($i=0;$i<=10;$i+=2) $sum+=$barcode[$i]; $r=$sum%10; if($r>0) $r=10-$r; return $r; } function TestCheckDigit($barcode) { //Test validity of check digit $sum=0; for($i=1;$i<=11;$i+=2) $sum+=3*$barcode[$i]; for($i=0;$i<=10;$i+=2) $sum+=$barcode[$i]; return ($sum+$barcode[12])%10==0; } function Barcode($x, $y, $barcode, $h, $w, $len) { //Padding $barcode=str_pad($barcode,$len-1,'0',STR_PAD_LEFT); if($len==12) $barcode='0'.$barcode; //Add or control the check digit if(strlen($barcode)==12) $barcode.=$this->GetCheckDigit($barcode); elseif(!$this->TestCheckDigit($barcode)) $this->Error('Incorrect check digit'); //Convert digits to bars $codes=array( 'A'=>array( '0'=>'0001101','1'=>'0011001','2'=>'0010011','3'=>'0111101','4'=>'0100011', '5'=>'0110001','6'=>'0101111','7'=>'0111011','8'=>'0110111','9'=>'0001011'), 'B'=>array( '0'=>'0100111','1'=>'0110011','2'=>'0011011','3'=>'0100001','4'=>'0011101', '5'=>'0111001','6'=>'0000101','7'=>'0010001','8'=>'0001001','9'=>'0010111'), 'C'=>array( '0'=>'1110010','1'=>'1100110','2'=>'1101100','3'=>'1000010','4'=>'1011100', '5'=>'1001110','6'=>'1010000','7'=>'1000100','8'=>'1001000','9'=>'1110100') ); $parities=array( '0'=>array('A','A','A','A','A','A'), '1'=>array('A','A','B','A','B','B'), '2'=>array('A','A','B','B','A','B'), '3'=>array('A','A','B','B','B','A'), '4'=>array('A','B','A','A','B','B'), '5'=>array('A','B','B','A','A','B'), '6'=>array('A','B','B','B','A','A'), '7'=>array('A','B','A','B','A','B'), '8'=>array('A','B','A','B','B','A'), '9'=>array('A','B','B','A','B','A') ); $code='101'; $p=$parities[$barcode[0]]; for($i=1;$i<=6;$i++) $code.=$codes[$p[$i-1]][$barcode[$i]]; $code.='01010'; for($i=7;$i<=12;$i++) $code.=$codes['C'][$barcode[$i]]; $code.='101'; //Draw bars for($i=0;$i<strlen($code);$i++) { if($code[$i]=='1') $this->Rect($x+$i*$w,$y,$w,$h,'F'); } //Print text uder barcode $this->SetFont('Arial','B',12); $this->Text($x,$y+$h+11/$this->k,substr($barcode,-$len)); } //Instanciation of inherited class $pdf=new PDF(); $pdf->AliasNbPages(); $pdf->AddPage(); //* here is part of barcode $pdf->EAN13(10, 120, $barcode1); $pdf->SetFont('Arial','B',12); $pdf->Output('ticket.pdf', 'I'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> </body> </html> How do I make it so that the bars still draw correctly, but they don't draw from the code, they draw from $barcode. or how do I put the value of $barcode into there.........currently it has to be a 8 digit $barcode and I believe 4-5 random numbers either on front or back. I want to be able to make $barcode have the value of an ean 13 barcode(which is how many numbers? 13 right?) and so that that is the only thing dictating barcode(I do know how to make it more numbers, but I cant do that because of the 5 random ones). does this make sense? Similar TutorialsHello, I'm interested in hiring someone if it's too difficult but possible, or doing it myself if isn't too much work (I know basic php) which I doubt. I want that when I scan an item with my barcode pistol it automatically changes something in my page. I mean, I have a delivery system, so when the package arrive I want just to scan the barcode of the package and that automatically changes the status in the client area on my php site to "Ready". What are the requirements, and if I need to hire someone what would be the estimated reasonable price to pay. Thanks a lot. Best Regards Hi, I'm trying to run an api from upcdatabase.com. I works fine but some barcodes are 8digits or 13digits, i need those barcodes to be changed by adding in zero's if 8 or subtracting 1 zero if 13. It needs to do this before being sent to the sever. Your help is really appreciated this should be simple but has got be stumped i don't know where to even put the code... here's what i've got so far. THANKYOOUUU FOR YOUR TIME! <?php extract($_GET); if(isset($upc)) { ?> <form method="get" action="<?php print $_SERVER[PHP_SELF]; ?>"> <p><input type="text" name="upc" value=""/></p> <p><input type="submit" value="Search"/></p> </form> <?php require_once 'XML/RPC.php'; $rpc_key = 'c737eb5b608f31e5fa022718860f1578cf2cc2a6'; // Set your rpc_key here // Setup the URL of the XML-RPC service $client = new XML_RPC_Client('/xmlrpc', 'http://www.upcdatabase.com'); // Construct the entire parameter list (an array) for the call. // The array contains a single XML_RPC_Value object, a struct. // The struct is constructed from a PHP associative array, and each // value needs to be an XML_RPC_Value object. $params = array( new XML_RPC_Value( array( 'rpc_key' => new XML_RPC_Value($rpc_key, 'string'), 'upc' => new XML_RPC_Value($_REQUEST['upc'], 'string'), ), 'struct')); // Construct the XML-RPC request. Substitute your chosen method name $msg = new XML_RPC_Message('lookup', $params); $upc_count = count($upc); If ($upc_count == 7){ echo '0000'.$upc; } elseif ($upc == 13) { echo '000'.$upc; } else { echo 'incorrect number of digits'; } //Actually have the client send the message to the server. Save response. $resp = $client->send($msg); //If there was a problem sending the message, the resp will be false if (!$resp) { //print the error code from the client and exit echo 'Communication error: ' . $client->errstr; exit; } //If the response doesn't have a fault code, show the response as the array it is if(!$resp->faultCode()) { //Store the value of the response in a variable $val = $resp->value(); //Decode the value, into an array. $data = XML_RPC_decode($val); //Optionally print the array to the screen to inspect the values echo "<pre>" . print_r($data, true) . "</pre>"; echo '<p>'.$data['status'].'</p>'; echo '<p>'.$data['upc'].'</p>'; echo '<p>'.$data['description'].'</p>'; }else{ //If something went wrong, show the error echo 'Fault Code: ' . $resp->faultCode() . "\n"; echo 'Fault Reason: ' . $resp->faultString() . "\n"; } } else { ?> <p>Enter a 12 digit UPC Barcode</p> <form method="get" action="<?php print $_SERVER[PHP_SELF]; ?>"> <p><input type="text" name="upc" value=""/></p> <p><input type="submit" value="Search"/></p> </form> Hi guys, to compliment my ORM. On the multiple choice sheets which are scanned into images and then interpreted with the OMR thier is a barcode (like the ones on stuff you buy from the shops), this barcode contains digits to decide the layout of the sheet and how to run the OMR. How can I get PHP to read and understand the barcode. The barcode is originally generated by PHP and now I need PHP to read it and convert to numbers which then I run against mySQL db to enable the OMR to read correctly. If anyone can suggest a script or method or even a different way to tackle the issue it would be greatly appreciated. Thanks in advance. This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=316549.0 Hello, I use barcodegen.1d for php5 v2.2.0 to make barcodes, and works fine. I can show OK in html page with this code: <img alt="" src="image.php"> <br> barcodegen creates a png image (image.php). My question is: Exists a script to export the image "image.php" to "image.jpg" for example image.php <?php // Including all required classes require('class/BCGFont.php'); require('class/BCGColor.php'); require('class/BCGDrawing.php'); // Including the barcode technology include('class/BCGcode128.barcode.php'); // Loading Font $font = new BCGFont('./class/font/Arial.ttf', 18); // The arguments are R, G, B for color. $color_black = new BCGColor(0, 0, 0); $color_white = new BCGColor(255, 255, 255); $code = new BCGcode128(); $code->setScale(2); // Resolution $code->setThickness(30); // Thickness $code->setForegroundColor($color_black); // Color of bars $code->setBackgroundColor($color_white); // Color of spaces $code->setFont($font); // Font (or 0) $code->parse('122222222-adm-a'); // Text /* Here is the list of the arguments 1 - Filename (empty : display on screen) 2 - Background color */ $drawing = new BCGDrawing('', $color_white); $drawing->setBarcode($code); $drawing->draw(); // Header that says it is an image (remove it if you save the barcode to a file) header('Content-Type: image/png'); // Draw (or save) the image into PNG format. $drawing->finish(BCGDrawing::IMG_FORMAT_PNG); ?> A basic convert script from png to jpg: <?php // Quality is a number between 0 (best compression) and 100 (best quality) function png2jpg($originalFile, $outputFile, $quality) { $image = imagecreatefrompng($originalFile); imagejpeg($image, $outputFile, $quality); imagedestroy($image); } png2jpg("image.php","image.jpg", 100); //convert to jpg ?> But this didn't work, I've the error: Warning: imagecreatefrompng(): 'image.php' is not a valid PNG file in /var/www/barcodegen.1d-php5.v2.2.0/convertir.php Bye! and thanks |