I am trying to print 850 character extended code pages using ZPL II on a Zebra S4M. Whenever one of the extended characters I.E. An ASCII value of> 127 is used. I get a window with different shades of gray instead of the actual value.
I am trying to print ± and ° (ALT + 0177 and ALT + 0176). I suspect its RawPrinterHelper, which I am trying to use (as downloaded from MS, and the other from CodeProject), however I cannot see where the character codes go wrong.
It is strange that printing directly from Notepad displays the correct characters, which makes me think that this is a problem with the raw class of the printer assistant.
I am not attached to using the Raw Printer Helper class, so if there is a better way to do this, I am more than happy to see them.
SAMPLE ZPLII
Without escaped characters
^XA
^FO30,200^AD^FH,18,10^FD35 ± 2 ° ^FS
^FS
^XZ
With escaped characters (tried both upper and lower case)
^XA
^FO30,200^AD^FH,18,10^FD35 _b0 2 _b1 ^FS
^FS
^XZ
Raw Printer Assistant
[StructLayout(LayoutKind.Sequential)]
public struct DOCINFO
{
[MarshalAs(UnmanagedType.LPWStr)]
public string printerDocumentName;
[MarshalAs(UnmanagedType.LPWStr)]
public string pOutputFile;
[MarshalAs(UnmanagedType.LPWStr)]
public string printerDocumentDataType;
}
public class RawPrinter
{
[
DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = false,
CallingConvention = CallingConvention.StdCall)]
public static extern long OpenPrinter(string pPrinterName, ref IntPtr phPrinter, int pDefault);
[
DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = false,
CallingConvention = CallingConvention.StdCall)]
public static extern long StartDocPrinter(IntPtr hPrinter, int Level, ref DOCINFO pDocInfo);
[
DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = true,
CallingConvention = CallingConvention.StdCall)]
public static extern long StartPagePrinter(IntPtr hPrinter);
[
DllImport("winspool.drv", CharSet = CharSet.Ansi, ExactSpelling = true,
CallingConvention = CallingConvention.StdCall)]
public static extern long WritePrinter(IntPtr hPrinter, string data, int buf, ref int pcWritten);
[
DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = true,
CallingConvention = CallingConvention.StdCall)]
public static extern long EndPagePrinter(IntPtr hPrinter);
[
DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = true,
CallingConvention = CallingConvention.StdCall)]
public static extern long EndDocPrinter(IntPtr hPrinter);
[
DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = true,
CallingConvention = CallingConvention.StdCall)]
public static extern long ClosePrinter(IntPtr hPrinter);
public static void SendToPrinter(string printerJobName, string rawStringToSendToThePrinter,
string printerNameAsDescribedByPrintManager)
{
IntPtr handleForTheOpenPrinter = new IntPtr();
DOCINFO documentInformation = new DOCINFO();
int printerBytesWritten = 0;
documentInformation.printerDocumentName = printerJobName;
documentInformation.printerDocumentDataType = "RAW";
OpenPrinter(printerNameAsDescribedByPrintManager, ref handleForTheOpenPrinter, 0);
StartDocPrinter(handleForTheOpenPrinter, 1, ref documentInformation);
StartPagePrinter(handleForTheOpenPrinter);
WritePrinter(handleForTheOpenPrinter, rawStringToSendToThePrinter, rawStringToSendToThePrinter.Length,
ref printerBytesWritten);
EndPagePrinter(handleForTheOpenPrinter);
EndDocPrinter(handleForTheOpenPrinter);
ClosePrinter(handleForTheOpenPrinter);
}
}
The actual correction from the accepted answer sets the character internationalization (code ^ CI27 ) to page code 1252.
^XA
^FO30,200^AD^CI27^FH,18,10^FD35 _b0 2 _b1 ^FS
^FS
^XZ