Barcode Generator Code in PHP
The Barcode Generator in PHP is a final year project for BSCS BSIT and MCS studensts. For this project,
- Generate a barcode dynamically
- Generate a barcode in code of your choice.
- Generate a barcode in desired type of card.
Functional requirements of Barcode Generator in PHP
-
- We can generate a bar code with our given code, type and label.
- The Barcode Generator in PHP supports printing and generating the barcode.
- The Barcode Generator in PHP supports downloading the generated barcode to an image (png).
barcode.php
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<?php require 'vendor/autoload.php'; extract($_POST); $generator = new Picqer\Barcode\BarcodeGeneratorPNG(); $code2 =''; foreach(str_split($code) as $key => $c){ $code2 .=$c; if(count(str_split($code)) != $key) $code2 .=' '; } ?> <div id="field"> <center><large><b><?php echo $label ?></b></large></center> <img src="data:image/png;base64,<?php echo base64_encode($generator->getBarcode($code, $type)) ?>"> <div id="code"><?php echo $code2 ?></div> </div> |
index.php
[cr ayon-68fd5020337fc898462452/]
test.php
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <style> table { font-family: arial, sans-serif; border-collapse: collapse; width: 100%; } td, th { border: 1px solid #dddddd; text-align: left; padding: 8px; } tr:nth-child(even) { background-color: #dddddd; } </style> </head> <body> <table id="preview-table"> <tr> <th>Company</th> <th>Contact</th> <th>Country</th> </tr> <tr> <td>Alfreds Futterkiste</td> <td>Maria Anders</td> <td>Germany</td> </tr> <tr> <td>Centro comercial Moctezuma</td> <td>Francisco Chang</td> <td>Mexico</td> </tr> <tr> <td>Ernst Handel</td> <td>Roland Mendel</td> <td>Austria</td> </tr> <tr> <td>Island Trading</td> <td>Helen Bennett</td> <td>UK</td> </tr> <tr> <td>Laughing Bacchus Winecellars</td> <td>Yoshi Tannamuri</td> <td>Canada</td> </tr> <tr> <td>Magazzini Alimentari Riuniti</td> <td>Giovanni Rovelli</td> <td>Italy</td> </tr> </table> <button id="export">Table Export</button> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script type="text/javascript" src="tableExport.js"></script> <script type="text/javascript" src="html2canvas.js"></script> <script type="text/javascript"> $('#export').on('click', function() { console.log('exporting'); //$('#preview-table').tableExport({type:'png',escape:'false'}); html2canvas($('#preview-table'), { onrendered: function(canvas) { var img = canvas.toDataURL("image/png"); //var img = canvas.toDataURL("application/octet-stream"); function saveAs(uri, filename) { var link = document.createElement('a'); if (typeof link.download === 'string') { document.body.appendChild(link); // Firefox requires the link to be in the body link.download = filename; link.href = uri; link.click(); document.body.removeChild(link); // remove the link when done } else { location.replace(uri); } } var uri = img.replace(/^data:image\/[^;]/, 'data:application/octet-stream'); //window.open(url); saveAs(uri, 'tableExport.png'); } }); }); </script> </body> </html> |
Note: The UPC code is a barcode symbology that is used all over the world for tracking trade items in stores. You can also buy UPC codes from upcs.com.