Sub Class_Globals
'Private fx As JFX
Private printString As String
Private feed As String
Private printerGen As String
Public Constant As Int = 32
End Sub
' "" = Mostrar lista
Public Sub Initialize(printer As String)
printerGen = printer
End Sub
'
public Sub addString(str As String)
If str.Length > Constant Then
str = str.SubString2(0,Constant + 1)
End If
feed = feed & str & Chr(10)
End Sub
'
public Sub centerText(str As String)
If str.Length > Constant Then
addString(str.SubString2(0,Constant + 1))
End If
Dim half As Int = (Constant - str.Length) / 2
For i = 1 To half
str = " "&str
Next
addString(str)
End Sub
'
Public Sub addnewline
feed = Chr(34) & "RISO SCOTTI" & Chr(34) & "585H1R" & Chr(10)
feed = feed & "1T"
End Sub
public Sub addnewLine2
feed = "{D1370,0817,1350|}"
feed = feed & Chr(10) & "{C|}"
feed = feed & Chr(10) & "{PV00;0160,0120,0062,0063,B,00,B=Tex Prime srl|}"
feed = feed & Chr(10) & "{PV01;0050,0250,0041,0042,B,00,B=Felpa Boucle Trifoglio|}"
feed = feed & Chr(10) & "{PV02;0050,0370,0041,0042,B,00,B=Bagno: Jeans|}"
feed = feed & Chr(10) & "{PV03;0050,0470,0041,0042,B,00,B=Colore: Azzurro|}"
feed = feed & Chr(10) & "{PV04;0050,0580,0041,0042,B,00,B=Peso Netto: 24,58 Kg|}"
feed = feed & Chr(10) & "{PV05;0050,0699,0041,0042,B,00,B=Metri: 375|}"
feed = feed & Chr(10) & "{XB00;0110,0810,A,3,03,0,0128,+0000000000,000,0,00=>51111222333245837>65|}"
feed = feed & Chr(10) & "{PV06;0193,0973,0034,0035,B,00,B=11112223332458375|}"
feed = feed & Chr(10) & "{XS;I,0001,0000C5000|}"
End Sub
'
public Sub print (stringa As String)
printString = Chr(10) & Chr(10) & Chr(10)
printString = ""
printString = printString & stringa 'feed
jo.RunMethod("printString", Array(printerGen, printString))
'Dim by() As Byte = jo.RunMethodjo("cut",Null)
'jo.RunMethod("printBytes",Array(printerGen,by))
End Sub
'
private Sub jo As JavaObject
Return Me
End Sub
'CP1252 , UTF-8, CP437
#If java
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.util.ArrayList;
import java.util.List;
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.MediaPrintableArea;
public void printString(String printerName, String text) {
try {
// find the printService of name printerName
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
PrintService printService[] = PrintServiceLookup.lookupPrintServices(
flavor, pras);
PrintService service = findPrintService(printerName, printService);
DocPrintJob job = service.createPrintJob();
byte[] bytes;
// important for umlaut chars
bytes = text.getBytes("UTF-8");
Doc doc = new SimpleDoc(bytes, flavor, null);
job.print(doc, null);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void printBytes(String printerName, byte[] bytes) {
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
PrintService printService[] = PrintServiceLookup.lookupPrintServices(
flavor, pras);
PrintService service = findPrintService(printerName, printService);
DocPrintJob job = service.createPrintJob();
try {
Doc doc = new SimpleDoc(bytes, flavor, null);
job.print(doc, null);
} catch (Exception e) {
e.printStackTrace();
}
}
private PrintService findPrintService(String printerName,
PrintService[] services) {
for (PrintService service : services) {
if (service.getName().equalsIgnoreCase(printerName)) {
return service;
}
}
return null;
}
public byte[] cut() {
byte[] cutP = new byte[] { 0x1d, 'V', 1 };
return cutP;
}
#end if
' Public int print(Graphics g, PageFormat pf, int page)
' throws PrinterException {
' If (page > 0) { /* We have only one page, And 'page' is zero-based */
' Return NO_SUCH_PAGE;
' }
'
' /*
' * User (0,0) Is typically outside the imageable area, so we must
' * translate by the X And Y values in the PageFormat To avoid clipping
' */
' Graphics2D g2d = (Graphics2D) g;
' g2d.translate(pf.getImageableX(), pf.getImageableY());
' /* Now we perform our rendering */
'
' g.setFont(new Font("Roman", 0, 8));
' g.drawString("Hello world !", 0, 10);
'
' Return PAGE_EXISTS;
' }