Liquid UI - Documentation - 6.03.01 Wsprint Functions

6.03.01 Wsprint Functions


There are a number of functions available that can be accessed through calling the print( ) function on a given instance of the 'Printer' class. These functions are as follows.


Constructor

The Constructor function intializes the PrinterService object, tries to access the printer and performs the setup necessary for printing to occur. To print to the default printer, the syntax is as follows:

a = new Printer( );

To print to any other printer than the default, use the following syntax:

a = new Printer('printerName');

For network printers, as explained previously, it is necessary to use the full network path.


Printing text

The printing text function is used to print a line of text and to pass a string to the print( ) function.Text is left-aligned by default, but it is possible to use the xPos option to align text to other postiions as well. The '\n' character can be used to move text to a new line. The default syntax is as follows:

a.print('Test');
a.print('\n Test 1');

To use the xPos option, the syntax is as follows:

a.print('Test');
a.print('\n Test 1');

It is also possible to use the functions in wsprint.js to align to center or right. These will be demonstrated in the Wsprint Javascript Functions section below.


Printing horizontal lines

To print a horizontal line, it is necessary to use the 'lineStyle' option together with the type of line to be drawn. The available options for the line type are as follows:

  • NORMAL
  • DOT
  • DASH

The syntax is as follows:

a.print({lineStyle:'DASH'});


Moving printing to a new page

To create a page break and move printing to a new page, we use the 'NEWPAGE' option. The syntax is shown below:

a.print({cmd:'NEWPAGE'});


Finishing and sending to printer

Once a print job is done, it is necessary to send it to the printer. This is done via the 'FLUSH' command. The syntax is as follows:

a.print({cmd:'FLUSH'});


Setting line spacing

To set the spacing between lines of text, we will utilize the 'spacing' option. The syntax is shown below:

a.print({spacing:20});


Setting margins

When setting margins, as we did in the earlier code sample, we will create an array specifying the margins. We will then assign the array name to the 'margin' option. To leave a specifc parameter unchanged from the default, use '-1' as the value. The syntax is as follows:

var iTOR = 20; 
var iBOTTOM = 20; var iLEFT = 20;
var iRIGHT = 20; var pMargin = [iTOP,iBOTTOM,iLEFT,IRIGHT]; a.print({margin:pMargin});


Setting text fonts

To set a font type, we can create a listing of font options and then assign the object to the font option. The syntax is as follows:

var aFont={type:"Time New Roman",size=15,color="Blue",italic:true,underline:true});  
a.print({font:aFont});


Setting font colors

There are two ways to set the color for a given font. Either the name of the color can be used as we did in the example above, or an array of Red Green and Blue values for a color can be created. The following color names are supported:

Aqua, Azure, Beige, Black, Blue, Violet, Brown, Crimson, Cyan, Gray, Navy, Light Green, Red

The syntax for a color name is as follows:

var aFont({color:"Brown"});

For an array, the syntax is shown below:

var iRcolor=200;
var iGcolor=210;
var iBcolor=100;
var color = [iRcolo,iGcolor,iBcolor];
var aFont{color:zColor} 


Getting printable page widths

It is possible to find the printable page width by using the 'printWidth' member of the Print object. The return value will offset the left and right margins from the page width. The syntax is as follows:

page_width=a.printWidth; 


Getting text width in pixels

It is also possible to find the width of a givesn piece of text in pixels. This is done by using the bPrint:false option with the given string of text. the syntax is shown below:

text_width=a.print({bPrint:false},str); 

Can't find the answers you're looking for?