如何使用EPL编程打印到Zebra打印机TLP 3842?打印机不支持Zebra打印机语言(ZPL),我正在使用PrintDocument()。我一直在解决这个问题两个星期,无法解决。这是我到目前为止在代码中实际可以运行打印机的内容:
private System.ComponentModel.Container Components;
private System.Windows.Forms.Button PrintButton;
private Font PrintFont;
private StreamReader StreamToPrint;
private void PrintButton_Click(Object Sender, EventArgs e)
{
try
{
StreamToPrint = new StreamReader("C:\\Users\\jcabrera\\Desktop\\MyFile.txt");
//string ZPL_STRING = "^XA^LL440,^FO50,50^A0N,50,50^FDTesting Zebra Printer^FS^XZ";
// ZPL Command(s)
try
{
PrintFont = new Font("Arial", 10);
PrintDocument PD = new PrintDocument();
PD.PrintPage += new PrintPageEventHandler(this.PD_PrintPage);
PD.Print();
}
finally
{
StreamToPrint.Close();
}
} catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void PD_PrintPage(object Sender, PrintPageEventArgs ev)
{
float linesPerPage = 0;
float yPos = 0;
int count = 0;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
string line = null;
// Calculate the number of lines per page.
linesPerPage = ev.MarginBounds.Height /
PrintFont.GetHeight(ev.Graphics);
// Print each line of the file.
while (count < linesPerPage &&
((line = StreamToPrint.ReadLine()) != null))
{
yPos = topMargin + (count *
PrintFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString(line, PrintFont, Brushes.Black,
leftMargin, yPos, new StringFormat());
count++;
}
// If more lines exist, print another page.
if (line != null)
ev.HasMorePages = true;
else
ev.HasMorePages = false;
}
private void InitializeComponent()
{
this.Components = new System.ComponentModel.Container();
this.PrintButton = new System.Windows.Forms.Button();
this.ClientSize = new System.Drawing.Size(504, 381);
this.Text = "Print Example";
PrintButton.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
PrintButton.Location = new System.Drawing.Point(32, 110);
PrintButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
PrintButton.TabIndex = 0;
PrintButton.Text = "Print the file.";
PrintButton.Size = new System.Drawing.Size(136, 40);
PrintButton.Click += new System.EventHandler(PrintButton_Click);
this.Controls.Add(PrintButton);
}
使用Windows应用程序项目。
答案 0 :(得分:0)
您需要将RawPrinterHelperClass添加到您的项目,然后像这样打印
string ZPL_STRING = "^XA^LL440,^FO50,50^A0N,50,50^FDTesting Zebra Printer^FS^XZ";
RawPrinterHelper.SendStringToPrinter("PrinterName", ZPL_STRING)
C#类 https://github.com/andyyou/SendToPrinter/blob/master/Printer/RawPrinterHelper.cs