FieldSoftware
Home

-----------------------------

.NetCF: C#-VB.Net
 Software Developers


PrinterCE.NetCF SDK
   General Info
   Download & Install
   Purchase & Pricing
   Upgrade from PrinterCE

Getting Started with:
 
C#   -   VB.Net

  Code Examples

Documentation
  PrinterCE for .Net CF
  AsciiCE for .Net CF
  BarcodeCE for .Net CF

eVC (C/C++/MFC), eVB:
  PrinterCE SDK

-----------------------------

Software Developers
  PrinterCE SDK
  PrinterCE.NetCF SDK
  PocketHTMLprint SDK

Special Topics
  Supported Printers
  Bluetooth Printing
  Network Printing

Printing Utilities
  PrintPocketCE
  PIEprint
  PocketPixPrint
  PocketShot
 
PocketClipPrint

Arcade Games
  SockOut
  MazeCraze

Contact Info

BarcodeCE for .NetCF - Developer's Guide
Namespace : FieldSoftware.PrinterCE_NetCF
DLLs : PrinterCE_NetCF.dll, PrCE_NetCF.dll
Class Name: BarcodeCE

BarcodeCE for .NetCF is derived from PrinterCE for .NetCF, so all PrinterCE functionality is available through an instance of BarcodeCE (see here for PrinterCE for .NetCF functions).

The PrinterCE.NetCF module contains the following print classes:

bullet PrinterCE for .NetCF: The primary class for printing text, images, drawing objects (lines, rectangles, etc) and much more.
bullet AsciiCE for .NetCF: A separate class that allows for printing pure ASCII text to any ASCII printer.
bullet 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:

bullet

Zip+4 Postnet postal code

bullet

UPC-A

bullet

UPC-E

bullet

EAN-13/UPC-13

bullet

EAN-8

bullet

Interleaved 2 of 5 with optional checksum

bullet

Code 39 (3 of 9) with optional checksum.

bullet

HIBCC standard format variant of Code 39

bullet

Code 128

bullet

UCC 128

bullet

Code 93

bullet

Extended Code 93

bullet

Codabar with optional checksum

bullet

MSI-Plessey code with Mod10, Mod1010 or Mod1110 checksums

For more general information on bar codes :

bullet

The Bar Code Book by Roger Palmer - THE place to go for all around technical information on various bar code symbologies and applications.

bullet

BarCode 1 - A Web of Information About Bar Codes

bullet

Information on Barcode Symbologies - also Barcode Basics

bullet

Barcodes FAQ by Azalea Software

bullet

Barcode Books and Magazines

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;
  }
}

 

BarcodeCE for NetCF Constructors

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);

Parameters

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  (default)

BarcodeCE throws an exception for any error found.

Example:
BarcodeCE bcode1 = new BarcodeCE(BarcodeCE.EXCEPTION_LEVEL.ABORT_JOB);

Remarks

If exception handling is enabled, BarcodeCE throws a "PrinterCEException" exception for exception errors found. To catch any PrinterCE, BarcodeCE or AsciiCE thrown exception use:

  catch (PrinterCEException exc) {...

With exception handling disabled, when an error occurs within BarcodeCE , the severity of the error is determined and BarcodeCE "remembers" this as appropriate and the host app uses StatusCheck to determine if an error condition was found.

For example, if a printer error occurs, the entire printing job must be aborted, so all calls to BarcodeCE will remember that it is aborting and this will be handled gracefully. This design allows the app that uses BarcodeCE to have a relaxed approach to error handling, even to the point of ignoring errors completely (although it would be kind to the user to do StatusCheck calls and display error dialog boxes as needed).

 

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);

 

BarcodeCE for NetCF Methods and Properties

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.

BarCodeHeight

Method: Returns the height of the selected barcode type. The height is in ScaleMode units

Syntax:
double BarCodeHeight(BARCODE_TYPE BarcodeType,bool withtext);
double BarCodeHeight(BARCODE_TYPE BarcodeType,BARCODE_FONTSIZE fsize,int hpercent);

Parameters

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%)

Draw2of5

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,BARCODE_FONTSIZE fsize,
    TYPE_2of5 type2of5,BARCODE_FIT fit,
int hpercent);

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
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%)

Returns 

Width of the barcode in ScaleMode units. If the barcode string is not a valid format, returns –1.

Remarks

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. 

DrawCode39

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,
bool withtext,
   
TYPE_39 type39,BARCODE_FIT fit,bool Extended);

double
DrawCode39(string drawstr,double x,double y,
BARCODE_FONTSIZE fsize,
   
TYPE_39 type39,BARCODE_FIT fit,int hpercent,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)
extended – If True, allows for full ASCII character set (128 chars) to be encoded. This requires 2 Code39 characters to be printed per character. If False, the basic (non-extended) Code39 character set is limited to 0-9,A-Z and 8 punctuation characters.
-----
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%)

Returns

Width of the barcode in ScaleMode units. If the barcode string is not a valid format, returns –1.

Remarks

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.

DrawCode128

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,
bool withtext,
   
TYPE_128 type128,BARCODE_FIT fit);

double DrawCode128(string drawstr,double x,double y,BARCODE_FONTSIZE fsize,
   
TYPE_128 type128,BARCODE_FIT fit
,int hpercent);

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
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%)

Returns

Width of the barcode in ScaleMode units. If the barcode string is not a valid format, returns –1.

Remarks

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.

DrawCode93

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,
bool withtext,
    BARCODE_FIT fit,bool Extended);
double DrawCode93(string drawstr,double x,double y,BARCODE_FONTSIZE fsize,
    BARCODE_FIT fit
,int hpercent,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
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%)

Returns

Width of the barcode in ScaleMode units. If the barcode string is not a valid format, returns –1.

Remarks

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.

DrawCodabar

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,
bool withtext,
   
TYPE_CODABAR typecodabar,BARCODE_FIT fit);
double DrawCodabar(string drawstr,double x,double y,BARCODE_FONTSIZE fsize,
   
TYPE_CODABAR typecodabar,BARCODE_FIT fit
,int hpercent);

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
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%)

Returns

Width of the barcode in ScaleMode units. If the barcode string is not a valid format, returns –1.

Remarks

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.

DrawMSI

Draws barcode of type MSI-Plessey - Any length string up to 15 numeric characters   

Syntax:
double DrawMSI(string drawstr,double x,double y,bool withtext,
   
TYPE_MSI typeMSI,BARCODE_FIT fit);

double DrawMSI(string drawstr,double x,double y,BARCODE_FONTSIZE fsize,
   
TYPE_MSI typeMSI,BARCODE_FIT fit
,int hpercent);

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
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%)

Returns

Width of the barcode in ScaleMode units. If the barcode string is not a valid format, returns –1.

Remarks

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.

DrawPostnet

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);

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

Returns

Width of the barcode in ScaleMode units. If the barcode string is not a valid format, returns –1.

Remarks

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.

DrawUPC

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,
   
BARCODE_FONTSIZE fsize,TYPE_UPC typeUPC,int typeUPCsystem,BARCODE_FIT fit,int hpercent);

Parameters

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%)

Returns

Width of the barcode in ScaleMode units. If the barcode string is not a valid format, returns –1.

Remarks

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.

UPC Barcode String Formats - Numeric strings with following formats:

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.

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:

bcode.DrawUPC("060033","95250","",x,y,true,BarcodeCE.TYPE_UPC.UPC_EAN13,5,BarcodeCE.BARCODE_FIT.MEDIUM);