ZPL II 扩展字符

发布于 2024-08-29 17:14:53 字数 3709 浏览 2 评论 0原文

我正在尝试使用 ZPL II 将扩展代码页 850 个字符打印到 Zebra S4M。每当扩展字符 IE ASCII 值 > 之一时使用 127 我得到一个不同灰度的框而不是实际值。

我正在尝试打印 ± 和 °(ALT+0177 和 ALT+0176)。我怀疑它是我尝试使用的 RawPrinterHelper(从 MS 下载的,另一个从 CodeProject 下载的),但是我看不到字符代码出错的地方。

奇怪的是,直接从记事本打印会呈现正确的字符,这让我相信这是原始打印机帮助程序类的问题。

我并不局限于使用 Raw Printer Helper 类,因此如果有更好的方法来做到这一点,我非常高兴看到它们。

示例 ZPLII 没有转义字符

^XA
^FO30,200^AD^FH,18,10^FD35 ± 2 ° ^FS
^FS
^XZ

使用转义字符(大小写都尝试过)

^XA
^FO30,200^AD^FH,18,10^FD35 _b0 2 _b1 ^FS
^FS
^XZ

Raw Printer Helper

[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);
    }
}

接受答案的实际修复 设置字符国际化(代码 ^ CI27 )到代码页 1252。

^XA
^FO30,200^AD^CI27^FH,18,10^FD35 _b0 2 _b1 ^FS
^FS
^XZ

I'm trying to print extended code page 850 characters using ZPL II to a Zebra S4M. Whenever one of the extended characters I.E. ASCII value > 127 is used I get a box of varying shades of grey instead of the actual value.

I'm trying to print ± and ° (ALT+0177 and ALT+0176). I suspect its the RawPrinterHelper I am trying to use (as downloaded from MS, and another from CodeProject) however I cant see where the character codes are going wrong.

Weirdly, printing direct from Notepad renders the correct characters, which leads me to believe it is a problem with the raw printer helper class.

I am not tied to using the Raw Printer Helper class so if there is a better way of doing it, I am more than happy to see them.

SAMPLE ZPLII
Without escaped chars

^XA
^FO30,200^AD^FH,18,10^FD35 ± 2 ° ^FS
^FS
^XZ

With escaped chars (tried both upper and lower case)

^XA
^FO30,200^AD^FH,18,10^FD35 _b0 2 _b1 ^FS
^FS
^XZ

Raw Printer Helper

[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);
    }
}

Actual Fix from the Accepted Answer set the Character Internationalisation ( Code ^CI27 ) to Code Page 1252.

^XA
^FO30,200^AD^CI27^FH,18,10^FD35 _b0 2 _b1 ^FS
^FS
^XZ

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帅气尐潴 2024-09-05 17:14:53

是的,阴影框包含这些字节代码,代码页为 1252。这无疑是打印机的默认代码页,1252 是西欧和美洲的 Windows 代码页。

您必须发送命令将代码页切换到 850。从来看手册,需要 ^CI 选择字符集 13。

将代码页保持在 1252 并更改字符代码是明智的。字形表位于手册的后面。

Yes, the shaded boxes have those byte codes, in code page 1252. Which no doubt is the default code page for the printer, 1252 is the Windows code page for Western Europe and the Americas.

You'll have to send a command to switch the code page to 850. Judging from the manual, that requires ^CI to select character set 13.

Keeping the code page at 1252 and changing your character codes instead would be wise. The glyph tables are in the back of the manual.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文