A real world example demonstrating whaat wsprint can do.
In this example, we will use all of the functions we discussed in the earlier examples to print out a formatted receipt. Although in this case we used hard-coded values, you can also use variables to pass in the actual product names and price values. This operation requires that we use both wsprint.dll and wsprint.js functions. The process is as follows.
The script is shown below.
System.LoadFile('wsprint.js');
function printReceipt() {
var a, b;
try {
a = new Printer('Microsoft XPS Document Writer');
var iTOP = 20;
var iBOTTOM = 20;
var iLEFT = 20;
var iRIGHT = 20;
var pMargin = [iTOP, iBOTTOM, iLEFT, iRIGHT];
var iRcolor=200;
var iGcolor=210;
var iBcolor=100;
var zColor=[iRcolor,iGcolor,iBcolor];
var aFont={type:"Times New Roman", size:20, color:zColor,italic:true};
a.print({font:aFont, margin:pMargin });
a.printCenterAlign('WALMART\n');
var row1=['Item','Quantity','Price'];
table1=[row1];
a.tablePrint(table1);
a.print({lineStyle:"DASH"});
aFont={size:20,italic:false};
a.print({font:aFont});
row2=['Lays Chips','3','5.00'];
row3=['Apple','4 LB','10.00'];
table2=[row2,row3];
a.tablePrint(table2);
a.print({lineStyle:"DASH"});
row4=['TOTAL','','15.00'];
table3=[row4];
a.tablePrint(table3);
a.print({lineStyle:"DASH"});
a.print('Items can only be returned within 30 days of purchase. You must have your orginal receipt');
}
catch(err) {
System.TraceOutput(err);
}
}
printReceipt();