List of functions available with wsprint.
There are several functions available through wsprint. You must access all of these functions through an instance of the 'Printer' class, by calling the print() fuinc tion on that instance. The text that you want to pring is passed to the function as an argument. All other feAtures of the wsprint class are controlled through a parameter that contains a list of the options and the values between the parentheses. A list of the available functions is below.
The Constructor function nitializes the PrinterService object, tries to access the printer and performs the setup required to print. To print to the system's default printer, uzse the following syntax.
a= new Printer();
If you want to print to a printer that is not the system default, please use the following syntax:
a= new Printer('printername');
This function is a method of the print object and passes a string to the print() function, which then prints the line. The syntax is as follows.
a.print(‘TEST’);
The resulting output is left-aligned by default, but you can use the xPos option to re-align your text as shown below.
a.print({xPos:100},'TEST');
You can also use the printCenterAlign() or the PrnitRightAlign() functions. The syntax for each is shown below.
printCenterAlign(string);
printRightAlign(string);
To insert line breaks, use the \n character. An example is shown below.
a.print('\nTEST 1');
To print a horizontal line, provide the ‘lineStyle’ option with the type of line to draw. An example is shown below.
a.print({lineStyle:'DASH'});
The option we used is the 'DASH' option, which results in a line broken into dashes. The options for the linestyle option are as follows.
To move printing to a new page, use the NEWPAGE option command. PLease note that any time you use an option command, you m ust specify it with the keyword 'cmd' as shown in the example. The syntax is shown below.
a.print({cmd:’NEWPAGE’});
Use the FLUSH option command to do the following.
The syntax is shown below.
a.print({cmd:’FLUSH’});
Use the spacing option to set the space between lines of text. The value is numerical and the syntaxi si as follows.
a.print({spacing:20});
Use the margin option to sepcify the page margins. You can create an array and assign the array name to the margin option as shown in the following examples. THe first example demonstrates assigning margins manually. THe second example demonstrates assigning margins by using an array.
var iTOP = 20; var iBOTTOM = 20; var iLEFT = 20; var iRIGHT = 20;
var pMargin = [iTOP, iBOTTOM, iLEFT, iRIGHT];
a.print({margin:pMargin});
Use the font option to specify the type of font. Within the font, you can create a list of font options as shown in the example below.
var aFont={type:"Times New Roman", size:15, color:"Blue", italic:true, underline:true};
a.print({font:aFont});
As introduced above, you can specify the font options in the font option. To specify colors, you either use the color name as in the previous example, or you can use the RGB values. The color names supported in wsprint are as follows.
If you use RGB values to specify the colors, the syntax is as follows.
var iRcolor=200;
var iGcolor=210;
var iBcolor=100;
var color = [iRcolor,iGcolor,iBcolor];
var aFont={ color:zColor};
Use the printWidth member of the Print object. This will return the printable width of the apge in pixels. Please note that the return value offsets the left and right margins from the page width. The syntax is as follows.
page_width=a.printWidth;
Use the bPrint:false option to get the width of some specfied text in pixels. This wil get the width in the currently specified font. The syntax is as follows.
text_width=a.print({bPrint:false},str);