-----------------------------
.NetCF: C#-VB.Net
Documentation eVC
(C/C++/MFC), eVB: ----------------------------- Software Developers Special Topics
Printing Utilities |
BarcodeCE
for .NetCF
- Developer's Guide
|
PrinterCE for .NetCF: The primary class for printing text, images, drawing objects (lines, rectangles, etc) and much more. | |
AsciiCE for .NetCF: A separate class that allows for printing pure ASCII text to any ASCII printer. | |
BarcodeCE for .NetCF: An optional class derived from PrinterCE that adds over a dozen barcode types to PrinterCE. |
Note: Since BarcodeCE is derived from PrinterCE, all PrinterCE methods and properties can be used by BarcodeCE.
The BarcodeCE control is available as an option to PrinterCE SDK. BarcodeCE uses the functions of PrinterCE for all printing tasks, allowing programs to freely intermix bar codes with all of the other printing capabilities of PrinterCE. The bar codes supported in BarcodeCE include:
Zip+4 Postnet postal code | |
UPC-A | |
UPC-E | |
EAN-13/UPC-13 | |
EAN-8 | |
Interleaved 2 of 5 with optional checksum | |
Code 39 (3 of 9) with optional checksum. | |
HIBCC standard format variant of Code 39 | |
Code 128 | |
UCC 128 | |
Code 93 | |
Extended Code 93 | |
Codabar with optional checksum | |
MSI-Plessey code with Mod10, Mod1010 or Mod1110 checksums |
For more general information on bar codes :
The Bar Code Book by Roger Palmer - THE place to go for all around technical information on various bar code symbologies and applications. | |
Barcodes FAQ by Azalea Software | |
Simple C# code for using the BarcodeCE class to print out "Hello World" and simple barcode:
BarcodeCE bcode =
null;
try
{
bcode =
new
BarcodeCE();
//Create instance of BarcodeCE class
bcode.SelectPrinter(true);
//Let user select printer, paper, etc
bcode.ScaleMode =
BarcodeCE.MEASUREMENT_UNITS.INCHES; //Make all
units in inches
bcode.DrawText("Hello World");
//Print "Hello World" on page
bcode.DrawUPC("781572", "31856", "90000",
0, 0.3, true,
BarcodeCE.TYPE_UPC.UPC_EAN13, 0,
BarcodeCE.BARCODE_FIT.TIGHT);
bcode.EndDoc();
//Done with this page - print it
}
catch (PrinterCEException
exc) {
if
(bcode!=null)
{
bcode.ShutDown();
//Done - free BarcodeCE resources
bcode=null;
}
MessageBox.Show("BarcodeCE
Exception","Exception");
}
finally
{
if
(bcode!=null)
{
bcode.ShutDown();
//Done - free BarcodeCE resources
bcode=null;
}
}
Create an instance of BarcodeCE using one of the following 4 overloaded versions:
Syntax: (4 overloaded versions):
public
BarcodeCE();
public BarcodeCE(string
initstr);
public BarcodeCE(EXCEPTION_LEVEL
exclevel);
public BarcodeCE(EXCEPTION_LEVEL exclevel,string
initstr);
string -
Developer's License Key used to unlock BarcodeCE. Default is for BarcodeCE to
run in evaluation mode. After evaluation time limit has expired on a
device, BarcodeCE will be locked and will not function.
EXCEPTION_LEVEL -
Sets level of errors that will cause an
exception, using EXCEPTION_LEVEL enumeration:
EXCEPTION_LEVEL Enumeration |
Description |
NONE |
BarcodeCE will not throw an exception - use StatusCheck to determine if an error has occurred. |
ABORT_JOB |
BarcodeCE throws an exception if the print job is aborted, either by serious error or user cancel. |
ALL |
BarcodeCE throws an exception for any error found. |
Example:
BarcodeCE bcode1 = new
BarcodeCE(BarcodeCE.EXCEPTION_LEVEL.ABORT_JOB);
With exception handling disabled, when an error occurs within
For example, if a printer error occurs, the entire
printing job must be aborted, so all calls to
BarcodeCE
Enumerations
BARCODE_FIT – Selects bar code bar and space widths:
BARCODE_FIT
Enumeration
|
Description
|
LOOSE |
Loosest fit - widest barcode |
MEDIUM |
Medium fit |
TIGHT |
Tighter |
TIGHTminus1 |
Narrowest barcode |
BARCODE_FONTSIZE - Selects if barcode text will be printed with the barcode. Each barcode has a default font size (selected by "DEFAULT_SIZE") which will be adequate for most applications. However, the developer can override the default font by selecting between 4 and 16 point fonts:
BARCODE_FONTSIZE
Enumeration |
Description |
NO_TEXT |
Do not include text with barcode |
DEFAULT_SIZE |
Use default font for text |
POINT04 |
Use 4 point font |
POINT05 |
Use 5 point font |
POINT06 |
Use 6 point font |
POINT07 |
Use 7 point font |
POINT08 |
Use 8 point font |
POINT09 |
Use 9 point font |
POINT10 |
Use 10 point font |
POINT11 |
Use 11 point font |
POINT12 |
Use 12 point font |
POINT13 |
Use 13 point font |
POINT14 |
Use 14 point font |
POINT15 |
Use 15 point font |
POINT16 |
Use 16 point font |
Example:
//Draw code reduced TIGHTminus1, at 75% of default height, using 6
pt font for text
wid = bcode.DrawCode128("CODE 128", 0,
y, BarcodeCE.BARCODE_FONTSIZE.POINT06,
BarcodeCE.TYPE_128.AUTO,
BarcodeCE.BARCODE_FIT.TIGHTminus1,75);
See PrinterCE Methods and Properties for additional methods and properties available to the BarcodeCE class. Below are methods and properties specific to BarcodeCE class only.
NOTE: Barcodes use the PrinterCE “Justify” properties (JustifyHoriz and JustifyVert) to allow for Left/Center/Right horizontal and Top/Center/Bottom vertical justification. For example, if the justify properties are both set to CENTER then the x,y coordinates will specify the page position where the center of the barcode will be drawn.
Method: Returns the height of the selected barcode type. The height is in ScaleMode units
Syntax:
double
BarCodeHeight(BARCODE_TYPE BarcodeType,bool
withtext);
BarcodeType – Selected barcode type:
BARCODE_TYPE Enumeration |
UPCEAN |
MSI |
CODE93 |
CODE128 |
CODABAR |
CODE39 |
CODE2of5 |
POSTNET |
WithTextFlag – true indicates
height should be calculated to include both barcode and text. false
returns height of barcode only.
-----
fsize - Specify font size - see BARCODE_FONTSIZE enumeration at top.
hpercent - Specify height of barcode as percentage of standard height
(range from 25% to 100%)
Draws barcode of type interleaved 2 of 5 – Numeric characters only – any number. If an odd # of characters, than a 0 is pre-appended to front
Syntax:
double
Draw2of5(string drawstr,double
x,double y,bool
withtext,
TYPE_2of5 type2of5,BARCODE_FIT fit);
double
Draw2of5(string drawstr,double
x,double y,
TYPE_2of5 type2of5,BARCODE_FIT fit,
drawstr – string to be “barcoded”.
x,y – coordinates on page where the barcode will be drawn (in ScaleMode
units).
withtext – true: add the text string below the barcode. false, draw only the
barcode
type2of5 – Sub-type of Code 2 of 5 to draw:
TYPE2of5 Enumeration |
Description |
BASE |
|
CHECKSUM |
Add optional modulus 10 checksum |
fit – Selects barcode bar and space widths
(see BARCODE_FIT Enumeration at top)
fsize - Specify font size - see BARCODE_FONTSIZE enumeration at top.
hpercent - Specify height of barcode as percentage of standard height
(range from 25% to 100%)
Width of the barcode in ScaleMode units.
If the barcode string is not a valid format, returns –1.
If x or y is a negative value then no barcode is actually drawn but the “width” returned is the actual width of this barcode.
Draws barcode of type Code39 (also known as Code
3 of 9) - Any length alpha-numeric string. If “extended”=FALSE,
character set is 0-9, A-Z, and following punctuation [- . SPACE * $ / +
%]. If extended=TRUE, supports full 128 ASCII character set using barcode pairs per character.
Syntax:
double
DrawCode39(string drawstr,double
x,double y,
TYPE_39 type39,BARCODE_FIT fit,bool
Extended);
Parameters
drawstr – string to be “barcoded”.
x,y – coordinates on page where the barcode will be drawn (in ScaleMode
units).
withtext – true: add the text string below the barcode. false, draw only the
barcode
Type39 – Sub-type of Code 39 to draw:
TYPE_39 Enumeration |
Description |
NORMAL |
|
CHECKSUM |
Add modulo 43 checksum to barcode |
HIBC |
Preappends a “+” at the start of the
barcode and appends modulo 43 check character at the end as adopted
by HIBCC |
fit – Selects barcode bar and space widths
(see BARCODE_FIT Enumeration at top)
fsize - Specify font size - see BARCODE_FONTSIZE enumeration at top.
hpercent - Specify height of barcode as percentage of standard height
(range from 25% to 100%)
Width of the barcode in ScaleMode units.
If the barcode string is not a valid format, returns –1.
If x or y is a negative value then no barcode is actually drawn but the “width” returned is the actual width of this barcode.
Draws barcode of type Code 128. Any length
alpha-numeric string, supporting full 128 ASCII character set. Allows
numeric data to be compacted by special “2 numeric digits per
character” encoding. If type128=TYPE128_UCC128, supports UCC-128
standard – restricted to exactly 19 numeric digits in the string
Syntax:
double
DrawCode128(string drawstr,double
x,double y,
TYPE_128 type128,BARCODE_FIT fit);
drawstr– string to be “barcoded”.
x,y – coordinates on page where the barcode will be drawn (in ScaleMode
units).
withtext – true: add the text string below the barcode. false, draw only the
barcode
type128 – Sub-type of Code 2 of 5 to draw:
TYPE_128
Enumeration |
Description |
AUTO |
Base type starts with one of 3 start chars (A,
B, or C) and adds mod 103 check char followed by stop code at end. |
UCC |
Fixed length 19 data digits. Adds “Start Code
C” & “FNC 1” characters at start plus Mod 10 and mod 103
check characters at end, followed by stop code. |
fit – Selects barcode bar and space widths
(see BARCODE_FIT Enumeration at top)
fsize - Specify font size - see BARCODE_FONTSIZE enumeration at top.
hpercent - Specify height of barcode as percentage of standard height
(range from 25% to 100%)
Width of the barcode in ScaleMode units. If the barcode string is not a valid format, returns –1.
If x or y is a negative value then no barcode is actually drawn but the “width” returned is the actual width of this barcode.
Draws barcode of type 93 - Any length string,
consisting of characters 0-9, A-Z and punctuation {- . SPACE $ / + %]. If
extended=True, supports full 128 ASCII character set.
Syntax:
double
DrawCode93(string drawstr,double
x,double y,
BARCODE_FIT fit,bool Extended);
BARCODE_FIT fit
drawstr – string to be “barcoded”.
x,y – coordinates on page where the barcode will be drawn (in ScaleMode
units).
withtext – true: add the text string below the barcode. false, draw only the
barcode
fit – Selects barcode bar and space widths (see
BARCODE_FIT Enumeration at top)
extended – If True: encodes full
ASCII char set (128 chars). If False, encodes 0-9, A-Z + 11 punctuation
chars.
-----
fsize - Specify font size - see BARCODE_FONTSIZE enumeration at top.
hpercent - Specify height of barcode as percentage of standard height
(range from 25% to 100%)
Width of the barcode in ScaleMode units. If the barcode string is not a valid format, returns –1.
If x or y is a negative value then no barcode is actually drawn but the “width” returned is the actual width of this barcode.
Draws barcode of type Codabar - Any length
string, consisting of characters 0-9 and punctuation - $ : / , +]. Also A,
B, C, D are supported as special start/stop characters.
Syntax:
double
DrawCodabar(string drawstr,double
x,double y,
TYPE_CODABAR
typecodabar,BARCODE_FIT fit);
TYPE_CODABAR
typecodabar,BARCODE_FIT fit
drawstr – string to be “barcoded”.
x,y – coordinates on page where the barcode will be drawn (in ScaleMode
units).
withtext – true: add the text string below the barcode. false, draw only the
barcode
typecbar – Sub-type of Codabar to draw:
TYPE_CODABAR Enumeration |
Description |
BASE |
|
CHECKSUM16 |
Add Checksum to barcode |
fit – Selects barcode bar and space widths
(see BARCODE_FIT Enumeration at top)
fsize - Specify font size - see BARCODE_FONTSIZE enumeration at top.
hpercent - Specify height of barcode as percentage of standard height
(range from 25% to 100%)
Width of the barcode in ScaleMode units. If the barcode string is not a valid format, returns –1.
If x or y is a negative value then no barcode is actually drawn but the “width” returned is the actual width of this barcode.
Draws barcode of type MSI-Plessey - Any length
string up to 15 numeric characters
Syntax:
double
DrawMSI(string drawstr,double
x,double y,
TYPE_MSI typeMSI,BARCODE_FIT fit);
drawstr – string to be “barcoded”.
x,y – coordinates on page where the barcode will be drawn (in ScaleMode
units).
withtext – true: add the text string below the barcode. false, draw only the
barcode
typeMSI – Sub-type of MSI to draw:
TYPE_MSI Enumeration |
Description |
MOD10 |
Adds 1 mod 10 checksum |
MOD1010 |
Adds 2 mod 10 checksums |
MOD1110 |
Adds on mod 11 checksum followed by one mod 10
checksum |
fit – Selects barcode bar and space widths
(see BARCODE_FIT Enumeration at top)
fsize - Specify font size - see BARCODE_FONTSIZE enumeration at top.
hpercent - Specify height of barcode as percentage of standard height
(range from 25% to 100%)
Width of the barcode in ScaleMode units. If the barcode string is not a valid format, returns –1.
If x or y is a negative value then no barcode is actually drawn but the “width” returned is the actual width of this barcode.
Draws Zip+4 Postnet postal code - Numeric string
5 or 9 characters long (9 if using +4 digits). Allows for a dash “-“
to separate the first 5 and last 4 digits (ie: 95709-1234).
Syntax: double DrawPostnet(string drawstr,double x,double y,bool withtext);
drawstr– string to be “barcoded”.
x,y – coordinates on page where the barcode will be drawn (in ScaleMode
units).
withtext – true: add the text string below the barcode. false, draw only the
barcode
Width of the barcode in ScaleMode units. If the barcode string is not a valid format, returns –1.
If x or y is a negative value then no barcode is actually drawn but the “width” returned is the actual width of this barcode.
Draws barcode of types: UPC-A, UPC-E,
EAN-13/UPC-13 and EAN-8 plus UPC system designation.
Syntax:
double
DrawUPC(string leftstr,string
rightstr,string extrastr,double x,double y,
bool
withtext,TYPE_UPC typeUPC,int typeUPCsystem,BARCODE_FIT fit);
double
DrawUPC(string leftstr,string
rightstr,string extrastr,double x,double y,
leftstring, rightstring, xtrastring – strings to be “barcoded” in UPC/EAN format. If a string is not used in a particular UPC format, send “” empty string. UPC versions A and E can include a 2 or 5 digit supplemental string (xtrastring) - used primarily for paperback books and periodicals.
x,y – coordinates on page where the barcode will be drawn (in
ScaleMode units).
withtext – true: add the text string below the barcode. false, draw only the
barcode
typeUPC – Sub-type of UPC to draw:
TYPE_UPC Enumeration |
Description |
UPC_A |
Encodes 2 five-digit
numbers. Preappends the UPC system number and adds checksum at end. |
UPC_E |
Encodes 1 five-digit
number |
UPC_EAN8 |
Encodes 7 digits plus
a checksum character (first 2 digits are EAN/JAN flag chars) |
UPC_EAN13 |
The “typeUPCsystem” digit is added to the first digit of leftstring to form a 2-digit country flag code. The remaining 5 digits of lefstring and the 5 digits of rightstring form the data values. A checksum character is automatically added at the end (see example below) |
typeUPCsystem – selects UPC system used (0-9).
Added to front of barcode (valid only for TYPE_UPC_A and TYPE_UPC_E
types)..
fit – Selects barcode bar and space widths
(see BARCODE_FIT Enumeration at top)
fsize - Specify font size - see BARCODE_FONTSIZE enumeration at top.
hpercent - Specify height of barcode as percentage of standard height
(range from 25% to 100%)
Width of the barcode in ScaleMode units. If the barcode string is not a valid format, returns –1.
If x or y is a negative value then no barcode is actually drawn but the “width” returned is the actual width of this barcode.
TYPE_UPC_A
: leftstring=5 digits & rightstring=5 digits. Xtrastring is optional
with 2 or 5 digit supplemental code. The “typeUPCsystem” digit is
preappended and a checksum is added at the end.
TYPE_UPC_E
: leftstring=6 digits & rightstring=0 digits. Xtrastring is optional
with 2 or 5 digit supplemental code.
TYPE_UPC_EAN8
: leftstring=7 digits & rightstring=0 digits. The first 2 digits are
country flag codes, followed by 5 data characters. A checksum character is
automatically added at the end.
TYPE_UPC_EAN13
:
leftstring=6 digits & rightstring=5 digits. The “typeUPCsystem”
digit is added to the first digit of leftstring to form a
2-digit country flag
code. The remaining 5 digits of lefstring and the 5 digits of rightstring
form the data values. A checksum character is automatically added at the
end.
bcode.DrawUPC(
For example, the 13-digit UPC code 5060033952504 would be encoded as
leading digit (5) to "typeUPCsystem", next 6 digits (060033) as "leftstring",
next 5 digits (95250) as "rightstring" and the final digit (4) would be
automatically calculated by BarcodeCE - so call might look like: