Printing bar codes in a Report or DataWindow

The quickest and simplest way to print bar codes is by using a Report or DataWindow. It is very easy to modify existing Reports or DataWindows to print bar codes, or to create new ones.

In PowerBuilder you design reports using the Report Painter or DataWindow Painter. Most people will use this method to print bar codes;

To print bar codes you must use the bar code functions in the supplied PowerBuilder Library (*.PBL). Before you can use these new functions in your application, you must follow these steps;

See: Declaring Global External Functions

See: Adding our PowerBuilder Library to an application.

See: Adding a library to the Library Search Path.

Before you start

The procedure for creating a Report is the same for creating a DataWindow.

- Run the Report Painter or DataWindows Painter.

Report Painter 
DataWindows Painter (Shift+F4)

Design your Report or DataWindow

You can print bar codes in any Report or DataWindows, designed using any Presentation Style.

Before you can print bar codes, you must do the following;

- Design your Report or DataWindow in the usual way.

Usually you would add Column objects for the fields you want to display or print, or Computed Field if you are printing expressions.

Test your Report or DataWindow

Before you print bar codes, it is a good idea to do the following;

- Test your report to see if it is printing the right data.

Use Print Preview to test your Report or DataWindows is displaying the data you want.

Print your data the way you want it

You should now have tested your Report or DataWindow, and it should print your data in the format you require. 

- If you are not able to print the data in the format you want;

See: Format or manipulate data in Reports or DataWindows

Your data can now be printed as bar codes.

Print your data as bar codes

Bar codes are printed using a Computed Field.

The following section explains how to add a Computed Field to your Report or DataWindow.

Adding a Computed Field to a Report or DataWindow design

To add a Computed Field object to a Report or DataWindow design, you must be in design mode.

To open your Report or DataWindow, open a Browser Window or Library Window.

Browser
Window Painter (Shift+F2)

If your Report or DataWindow is already open in Print Preview;

- Select menu Design | Preview and uncheck Preview if it is checked.

- or use the Preview button to exit Print Preview mode.

To add a Computed Field object to your Report or DataWindow design;

- Select menu Objects | Computed Field.

- Click on your Report or DataWindow design in the position you want the new field to be created.

- In the Computed Object dialog box you can enter a Name for the object and the PowerBuilder Expression to calculate each time the field is displayed or printed.

Computed Field dialog box

Name:

In the Name box you should enter a unique name for the new Computed Field object. The name must not be the name of any; field, object or reserved word.

Note: The Name property can be used to reference the value of the Computed Field object in other objects, or in PowerBuilder scripts.
Expression:

The Expression property of a Computed Field object is used to return a value which is displayed or printed.

For example, this expression uses bar code functions cia_code128( ) to return the Code 128 bar code containing the client_number field.

cia_code128 ( client_number )

See: Bar code functions for a complete list of the new bar code functions

Each bar code function takes a string argument and returns a string result. The string argument is the data you want to encode in the bar code. The string result will be printed by the Computed Field automatically. The string will print as a bar code because you will also use a specific bar code font.

Selecting a bar code font

The final task is to print the Computed Field using a bar code font.

- In your Report or DataWindow, select the Computed Field object you want to print as a bar code.

Note: For each bar code function, there is a font and font size to use. 

See: Bar code font name and font size to use to discover the font and font size to select.

- Set the Font and Font Style and Size property.

- Click the Position tab and check the Autosize Height box.

Bar code fonts should always be printed using Font Style set to Regular (never Bold).

For example, to print Code 128 bar codes use font name CIA Code 128 Medium and font size 14.

Design mode

In report design mode, when you select a bar code font, the Computed Fields will often display boxes. This is because, in design mode, the Computed Field expression in being displayed, not the Computed Field result

The correct results are displayed only when you use Print or Print Preview.

This shows a report design in design mode;

Print Preview mode

When you Print the report, or Print Preview the report, all Computed Fields return a result

The result automatically print the correct bar code. 

To see the result displayed correctly, use Print Preview;

- Click the Preview button on the toolbar.

This shows the same report as above, but now in Print Preview mode;

Sizing the Computed Field object

If your Computed Field is not wide enough, bar codes will be cropped when they are print.

IMPORTANT: When you print text, it is easy to check if text has been printed correctly, because you can read the text and you can see characters are missing from the end (cropped). When you print bar codes, it is difficult to see if one or two bars are missing from the end (cropped). Often this is only notice when you use a bar code reader to read the bar code.

To prevent any chance of cropping, size the Computed Field so that the right side is at the right side of the page.

TIP: If you are printing labels, print bar codes on the left, then you have more space to print all possible field values as bar codes.

- To save the Report or DataWindow design, choose menu File | Save.

Printing human-readable text below the bar code

Some bar code fonts automatically print the human-readable text below the bar code, and some fonts do not. When you use Print Preview, to view the output of your Report or DataWindow, you will see if the font automatically prints the human readable text.

Font 'CIA UPC' automatically prints text below the bar code.

Font 'CIA ITF Normal' does not print text below the bar code.

We provide fonts that do not print human-readable text, so that you can use a separate Column or Computed Field to print the human-readable text using any regular text font you want (Arial, Courier, Times, etc.) and in any position you want (above, below, etc.). You can also use any text font size (independently of the bar code size).

Note: If the bar code standard specifies, either;
  • check characters are displayed in the human-readable text (e.g. ITF, UPC, EAN).
  • human-readable text should be formatted in a special way (e.g. SSCC-18).

then you will find a separate bar code functions that returns human-readable text ( to print separately underneath bar code, or elsewhere).

 


Copyright 2000 CIA (BAR CODES) UK. All rights reserved. Reproduction prohibited.