Sample Code 480: How to print barcode label - Part 2 - UPC A barcodes? |
|
Written by kksou
|
|
Thursday, 17 April 2008 |
|
Problem In How to print barcode label - Part 1 - EAN13 barcodes? we have printed EAN13 barcodes on a receipt printer using the ESC/POS commands.
In this Part 2, we will print UPC-A barcodes.
The UPC-A is a barcode system widely used in the United States and Canada, especially for items in the retail stores. It's a 12-digit number with the last number as the check digit as shown below.
To know what each digit means, please refer to the UPC-A Specification.

Solution Below are the steps for printing UPC-A barcodes:
- Select the barcode font.
- Select where to print the barcode text (above, below or none).
- Set the width and height of the barcode.
- Inform the printer that the barcode is in UPC-A format.
- Sends the UPC-A barcode to the printer. Note that you can send this as a 11-digit number (without the check digit) or a 12-digit number (with the check digit).
Sample Code 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
| <?php $window = new GtkWindow(); $window->set_size_request(400, 150); $window->connect_simple('destroy', array('Gtk','main_quit')); $window->add($vbox = new GtkVBox());
// display title
$title = new GtkLabel("Print Barcode Label (EAN13 only)"); $title->modify_font(new PangoFontDescription("Times New Roman Italic 10")); $title->modify_fg(Gtk::STATE_NORMAL, GdkColor::parse("#0000ff")); $title->set_size_request(-1, 40); $vbox->pack_start($title, 0, 0);
$hbox = new GtkHBox(); $vbox->pack_start($hbox, 0, 0); $hbox->pack_start(new GtkLabel("Enter/Scan Barcode: "), 0, 0); $hbox->pack_start($entry = new GtkEntry(), 0, 0); $hbox->pack_start($button = new GtkButton("Print Label"), 0, 0);
$entry->set_text('012345678912'); $entry->connect('activate', 'on_enter', $button); $button->connect('clicked', 'on_click', $entry); $window->show_all(); Gtk::main();
function on_enter($entry, $button) { $keyword = $entry->get_text(); $button->clicked(); }
function on_click($button, $entry) { $barcode = $entry->get_text();
|
- Note that this is only 70% of the sample code. You have to be a registered member to see the entire sample code. Please login or register.
- Registration is free and immediate.
- Have some doubt about the registration? Please read this forum article.
Explanation
- Establish the connection with the receipt printer through PRN.
- Please refer to Barcode printing on receipt printer using the ESC/POS Commands for explanations of these settings.
- Sends the UPC-A barcode to the printer. You will now see the UPC-A barcode printed on the receipt printer! Note that this must be either 11 digits (without the checkdigit) or 12 digits (with the check digit).
- Done!
Related Links
Resources on barcodes
Here are some useful links on barcodes:
|
Add comment
Latest Blog Articles
|
Wednesday, 23 February 2011 For the googleMaps plugin users, the native version for Joomla 1.6 is now available!
Download: googleMaps v1.6 |
|
|
Monday, 21 February 2011 For the DirectPHP users, the native version for Joomla 1.6 is now available!
Download : DirectPHP v1.6 |
|
|
Monday, 14 February 2011 I've published more than 40 Joomla Extensions in joomla.org.
Recently I've received a couple of requests to upgrade these plugins/modules to Joomla 1.6.
Some of these are written 3 years ago. I'm not sure if any of you are still using them at all.
So send me a tweet @kksou if you want any of them to be converted to Joomla 1.6. Drop me a note to let me know that they are useful. I don't have the time to convert all the extensions. There has to be some priorities somewhere. So I will start with the plugin/module with more than a hundred requests for conversion. |
|
|