Στο βιβλίο “.net compact framework programming with cSharp” υπάρχει η παρακάτω μέθοδος για εκτύπωση σε network printer με sockets. Δουλεύει μια χαρά με τον posiflex θερμικό receipt printer που έχω. Δεν μπορεί όμως να τυπώσει Ελληνικούς χαρακτήρες παρόλο που το Dell Axim με Windows CE 5 διαθέτει Ελληνικά. Φαντάζομαι, αυτό έχει να κάνει με την συγκεκριμένη υλοποίηση και ψάχνω να βρω μια λύσει.
Ψάχνω να βρω έναν τρόπο να τυπώνω από το PDA στον Posiflex network receipt printer, Ελληνικά. Με την χρήση του Printer CE και λοιπών εφαρμογών δεν έχω θετικό αποτέλεσμα.
Κάθε βοήθεια ευπρόσδεκτη
Ευχαριστώ
---------
Listing 17.5. Direct Printing to an IP Printer (from PrintJob_Socket.ca)
public class PrintJob_Socket
{
private const byte CR = 0x0a;
private const byte LF = 0x0d;
private const byte FF = 0x0c;
//--------------------------------------------------------
//--------------------------------------------------------
public static void PrintText(TextBox textIn, string strPort)
{
// Split the input data into separate lines of text.
char [] achNewLine = new char[] { '\n' };
String [] astrSplit;
astrSplit = textIn.Text.Split(achNewLine);
// Calculate the longest string in the document.
int cchMax = 0;
int cstr = astrSplit.Length;
for (int i = 0; i < cstr; i++)
{
if (astrSplit
.Length > cchMax)
cchMax = astrSplit
.Length;
}
// Allocate the conversion buffer.
byte[] byteData = new Byte[cchMax];
char[] chData = new Char[cchMax];
System.Text.Encoder d;
d = System.Text.Encoding.UTF8.GetEncoder();
Socket s = null;
try
{
// Connect to the printer.
s = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.IP);
IPAddress addr = IPAddress.Parse(strPort);
IPEndPoint ipep = new IPEndPoint(addr, 9100);
s.Connect(ipep);
// Loop through the list of strings.
for (int i = 0; i < cstr; i++)
{
int cch = astrSplit
.Length;
if (cch > 0)
{
chData = astrSplit
.ToCharArray();
// Convert the Unicode string to UTF-8 encoding.
d.GetBytes(chData, 0, cch, byteData, 0, true);
// Output the bytes to the printer.
s.Send(byteData,0, cch,SocketFlags.None);
}
// Put a carriage return at the line end.
byte[] byteCrLf = new byte[] { CR };
s.Send(byteCrLf,0, 1,SocketFlags.None);
}
// Put a form feed at the end of the document.
byte[] byteFF = new byte[] { FF };
s.Send(byteFF,0, 1,SocketFlags.None);
}
finally
{
s.Close();
}
}
//--------------------------------------------------------
public static bool IsIPAddress(string strIn)
{
bool bRetVal = true;
try
{
IPAddress.Parse(strIn);
}
catch
{
bRetVal = false;
}
return bRetVal;
}
} // class