Text line order is changed when printed through parallel printer

  • Thread starter Thread starter Jeff0803
  • Start date Start date
J

Jeff0803

Guest
I made parallel printing module like following.

public int PrintText(string parallelport, string receiptText, Int16 nLen, Encoding encoding)
{
IntPtr ptr = CreateFile(parallelport, GENERIC_WRITE, 0,
IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero);

/* Is bad handle? INVALID_HANDLE_VALUE */
if (ptr.ToInt32() == -1)
{
/* ask the framework to marshall the win32 error code to an exception */
// Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
return (-1);
}

FileStream lpt = new FileStream(ptr, FileAccess.ReadWrite);
Byte[] buffer = new Byte[2048];

//Check to see if your printer support ASCII encoding or Unicode.
//If unicode is supported, use the following:
if (encoding == Encoding.Unicode)
{
buffer = System.Text.Encoding.Unicode.GetBytes(receiptText);
}
else if (encoding == Encoding.ASCII)
{
buffer = System.Text.Encoding.ASCII.GetBytes(receiptText);
}
lpt.Write(buffer, 0, buffer.Length);
lpt.Close();
return (0);
}

This module works fine when save as a file.

However the line order is changed when printer to a parallel printer.

For example, if following string is passed to the parallelport,

AAAA
BBBBBBBB
CCCCCCC
DDD

Then the output result is always like following.

BBBBBBBB
CCCCCCC
DDDAAAA


Can anybody give me some advice?

Continue reading...
 
Back
Top