我可以在Zebra GX430t打印机上打印标签而不发送原始文本

时间:2017-06-06 17:13:10

标签: c# printing rdp zebra-printers

我在C#中创建了一个创建标签格式的应用程序,并以ZPL II格式将它们发送到Zebra打印机。为了使打印机正常运行,我需要使用pinvoke调用将打印机原始文本发送到winspool.Drv dll。它工作正常,直到我们在我们的一个客户上尝试使用RDP远程访问我们的服务器。事实证明,打印机通过RDP重定向使用EasyPrint和EasyPrint阻止RawPrinterHelper调用并防止打印任何内容。我的网络用户声称,如果不打破服务器上所有其他重定向的打印机,我们就无法关闭它。

我注意到打印机的默认驱动程序似乎表现为“普通”打印机。我正在尝试使用此默认驱动程序(ZDesigner GX430t)找到一种方法将标签打印到此打印机。我似乎无法找到任何关于这样做的文档。我将尝试使用标准的C#命令以任何其他打印机的方式绘制到打印机,但我想确保我没有遗漏任何东西。还有其他人做过这样的事吗?

1 个答案:

答案 0 :(得分:1)

好的,感谢ScanTexas的人们,我想我找到了解决方案。 打印机驱动程序具有允许“通过”字符的设置。您可以在PrintDocument中包含这些内容,只需在标签前加上起始字符'$'',并在末尾追加结束字符'} $'。以下是说明: pass thru instructions

这是我的测试代码(winform表单):

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;

namespace ZebraPrint
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void Button1_Click(object sender, System.EventArgs e)
        {
            using (PrintDocument doc = new PrintDocument())
            {
                doc.PrintPage += new PrintPageEventHandler(document_PrintPage);

                using (PrintDialog pd = new PrintDialog())
                {
                    pd.PrinterSettings = new PrinterSettings();
                    pd.Document = doc;
                    if (pd.ShowDialog(this) == DialogResult.OK)
                    {
                        pd.Document.Print();
                    }
                }
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void document_PrintPage(object sender, PrintPageEventArgs e)
        {
            Font printFont = new Font("Consolas", 6);
            SizeF size = e.Graphics.MeasureString("WWWWWW", printFont);
            float printTextHeight = size.Height;
            float top = 0;

            e.Graphics.DrawString(@"${^XA", printFont, System.Drawing.Brushes.Black, 10, top += printTextHeight);
            e.Graphics.DrawString(@"^MD0", printFont, System.Drawing.Brushes.Black, 10, top += printTextHeight);
            e.Graphics.DrawString(@"^MMT", printFont, System.Drawing.Brushes.Black, 10, top += printTextHeight);
            e.Graphics.DrawString(@"^MNY", printFont, System.Drawing.Brushes.Black, 10, top += printTextHeight);
            e.Graphics.DrawString(@"^LL600", printFont, System.Drawing.Brushes.Black, 10, top += printTextHeight);
            e.Graphics.DrawString(@"^LH95,75", printFont, System.Drawing.Brushes.Black, 10, top += printTextHeight);
            e.Graphics.DrawString(@"^FO0,0^AA,54^FD  Palmdale Oil Company, Inc.^FS", printFont, System.Drawing.Brushes.Black, 10, top += printTextHeight);
            e.Graphics.DrawString(@"^FO0,100^AC,36^FDCustomer: AVERITT EXPRESS^FS", printFont, System.Drawing.Brushes.Black, 10, top += printTextHeight);
            e.Graphics.DrawString(@"^FO0,136^AC,36^FD Vehicle: 66030^FS", printFont, System.Drawing.Brushes.Black, 10, top += printTextHeight);
            e.Graphics.DrawString(@"^FO0,172^AC,36^FD    Desc: REEFER^FS", printFont, System.Drawing.Brushes.Black, 10, top += printTextHeight);
            e.Graphics.DrawString(@"^FO0,208^AC,36^FD     TAG: ^FS", printFont, System.Drawing.Brushes.Black, 10, top += printTextHeight);
            e.Graphics.DrawString(@"^FO0,275", printFont, System.Drawing.Brushes.Black, 10, top += printTextHeight);
            e.Graphics.DrawString(@"^BY5", printFont, System.Drawing.Brushes.Black, 10, top += printTextHeight);
            e.Graphics.DrawString(@"^BC,150,N,N,N,N^FD4770013-66030", printFont, System.Drawing.Brushes.Black, 10, top += printTextHeight);
            e.Graphics.DrawString(@"^FS", printFont, System.Drawing.Brushes.Black, 10, top += printTextHeight);
            e.Graphics.DrawString(@"^FO0,430^AC,36^FD4770013-66030^FS", printFont, System.Drawing.Brushes.Black, 10, top += printTextHeight);
            e.Graphics.DrawString(@"^XZ}$", printFont, System.Drawing.Brushes.Black, 10, top += printTextHeight);
        }
    }
}