PHP-GTK2 Newsletter

PHP-GTK2 Tips & Techniques
FREE Newsletter
by kksou



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.

How to print barcode label - Part 2 - UPC A barcodes?


Solution

Below are the steps for printing UPC-A barcodes:

  1. Select the barcode font.
  2. Select where to print the barcode text (above, below or none).
  3. Set the width and height of the barcode.
  4. Inform the printer that the barcode is in UPC-A format.
  5. 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
  1. Establish the connection with the receipt printer through PRN.
  2. Please refer to Barcode printing on receipt printer using the ESC/POS Commands for explanations of these settings.
  3. 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).
  4. Done!

Related Links

Resources on barcodes

Here are some useful links on barcodes:

 

Add comment


Security code
Refresh

< Prev   Next >

Blog - Forum - Privacy Policy - Contact Us
Links - Classes - Social Business - BPM - Web - General
Copyright © 2006-2013. kksou.com. All Rights Reserved