IMPORTANT: Bar codes can easily be printed using a Report or DataWindow, designed in PowerBuilder's Report Painter or DataWindow Painter. It is very easy to modify existing Reports or DataWindows to print bar codes, or to create new ones. 

See: Printing bar codes in a Report or DataWindow

Only resort to PowerScript code if a Report or DataWindow is not sufficient.

Most people will use a Report or DataWindow to print bar codes.

Example

Printing data from a DataWindow as bar codes using PowerScript code

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: Adding our PowerBuilder Library to an application

See: Adding a library to the Library Search Path.

Printing using PowerScript

PowerBuilder has a set of PowerScript functions to handle printing; PrintOpen( ), PrintSend( ), PrintDefineFont( ), PrintSetFont( ), Print( ), PrintX( ), PrintY( ), PrintText( ), PrintPage(), PrintClose( ).

See the PowerBuilder Help for full details of all of these functions.

The example is very simple, it prints some static text and a fixed bar code. 

You could expand this example to get records from a DataWindows and print them, with some fields printed as bar codes as a; form, report or labels.

int li_print_ret
long ll_print_job

// Open print job and assign job number
ll_print_job = PrintOpen( )				
if ll_print_job < 0 then
	MessageBox("Error in PrintOpen", ll_print_job, StopSign!)
	return
end if

// Define fonts 1 and 2
li_print_ret = PrintDefineFont(ll_print_job, 1, "Arial", -10, 700, Default!, AnyFont!, False, False)
li_print_ret = PrintDefineFont(ll_print_job, 2, "CIA Code 128 Medium", -14, 400, Default!, AnyFont!, False, False)

// Set font 1
li_print_ret = PrintSetFont(ll_print_job, 1)
li_print_ret = Print( ll_print_job, "Here is a Code 128 bar code containing 0123456789" )

// Restore default font and print 2 blank lines
li_print_ret = PrintSetFont(ll_print_job, 0)
li_print_ret = Print(ll_print_job, " ")
li_print_ret = Print(ll_print_job, " ")

// Set font 2
li_print_ret = PrintSetFont(ll_print_job, 2)
li_print_ret = Print( ll_print_job, CIA_CODE128( "0123456789" ) )

// Close print job
li_print_ret = PrintClose(ll_print_job)
if li_print_ret < 0 then
	MessageBox("Error on PrintClose", li_print_ret, StopSign!)
end if

 

 


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